【发布时间】:2012-06-30 00:30:52
【问题描述】:
我正在 J2ME 中开发一些发送和接收加密消息的应用程序,我发现下面的代码将其加密并转换为字符串,但它不起作用并抛出异常,我应该怎么做?当我想解密时,我应该如何将 String 转换为 byte[] ?谢谢
byte[] plainArray = message.getBytes();
try {
byte[] keyBytes = "SECRET_1SECRET_2SECRET_3".getBytes();
// key = new KeyParameter(keyBytes);
AESEngine engine = new AESEngine();
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(engine);
cipher.init(true, new KeyParameter(keyBytes));
byte[] cipherBytes = new byte[cipher.getOutputSize(plainArray.length)];
int cipherLength = cipher.processBytes(plainArray, 0, plainArray.length, cipherBytes, 0);
cipher.doFinal(cipherBytes, cipherLength);
String result2 = org.apache.commons.codec.binary.Base64.encodeBase64String(cipherBytes);
formSender.append(result2);
} catch (Exception e) {
}
例外:
TRACE: , 捕获到异常 在显示类 java.lang.Error: ClassFormatError: 56 at SSMS.EncShow(), bci=173 at SSMS.commandAction(), bci=16 at javax.microedition.lcdui.Display$ChameleonTunnel.callScreenListener(), bci=44 在 com.sun.midp.chameleon.layers.SoftButtonLayer.processCommand(), bci=80 在 com.sun.midp.chameleon.layers.SoftButtonLayer.soft1(),bci=31 在 com.sun.midp.chameleon.layers.SoftButtonLayer.keyInput(),bci=48 在 com.sun.midp.chameleon.CWindow.keyInput(), bci=38 at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handleKeyEvent(), bci=32 在 com.sun.midp.lcdui.DisplayEventListener.process(),bci=294 在 com.sun.midp.events.EventQueue.run(),bci=177 在 java.lang.Thread.run(Thread.java:722)
【问题讨论】:
标签: java java-me base64 bouncycastle