我需要使用CBC Rijndael加密對文本進行編碼/解碼。Bouncycastle java編碼/解碼。缺少字節?
輸入: 力是強在這個looooooooooooooooooo000000000oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong字符串
編碼輸入:†'Ú½mÎ-「AŽyÝ¢ƒô] 5X-A;「BC†.Ìμ¼èüÈíÖXÈ*©Ã¼ç,hKBμ $híƒEu-ȸU¤'AÓÈÿ?æûä¸:OW?B>ÐZ¡ ,zëë(C'®5ÐixRÉp% ì%q'ÕQÚ5μッ
解碼輸入: 「的力量是強大的在這looooooooooooooooooo000000000ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo」 - 在地方結束的32位(字節值是0)
我錯過了最後的字節。誰能告訴我爲什麼?
這是我的代碼:
公共類BouncyDecoder {
byte[] IV = null;
byte[] encryptionKey = null;
Cipher cipher;
SecretKeySpec key;
BlockCipher blockCipher;
ParametersWithIV _param;
PaddedBufferedBlockCipher mode;
int blockSize;
public BouncyDecoder() {
Security.addProvider(new BouncyCastleProvider());
try {
IV = "1234567891234567891234567891234".getBytes("UTF-8");
encryptionKey = "1234567891123453456789123456781".getBytes("UTF-8");
blockCipher = new CBCBlockCipher(new RijndaelEngine(256));
_param = new ParametersWithIV(new KeyParameter(encryptionKey), IV);
mode = new PaddedBufferedBlockCipher(blockCipher);
blockSize = blockCipher.getBlockSize();
} catch (Exception e) {
}
}
public byte[] decrypt(byte[] encodedText) {
byte[] decoded = new byte[mode.getOutputSize(encodedText.length)];
try {
mode.init(false, _param);
int bytesProcessed = 0;
int i=0;
for (i = 0; i < (encodedText.length/32) ; i++){
bytesProcessed += mode.processBytes(encodedText, i * blockSize, blockSize, decoded, bytesProcessed);
}
mode.doFinal(decoded, (i-1)*blockSize);
} catch (Exception e) {
}
return decoded;
}
public byte[] encrypt(byte[] normalText) {
byte[] encryptedText = new byte[mode.getOutputSize(normalText.length)];
try {
mode.init(true, _param);
int bytesProcessed = 0;
int i=0;
for (i = 0; i < (normalText.length/32); i++) {
bytesProcessed += mode
.processBytes(normalText, i * blockSize, blockSize, encryptedText, bytesProcessed);
}
mode.doFinal(encryptedText, (i-1)*blockSize);
} catch (Exception e) {
e.printStackTrace();
}
return encryptedText;
}
}
我的臉我的臉ᵒh神,不,不拿去ONΘ停止安排* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ŝ –