iPhone如何加密AES256输出32字节十六进制字符串?
亲爱的大师们, 我在带有充气城堡库的java上有代码,如下所示:
private static String AES (boolean encrypt, String inputString, String keyString) {
byte [] input, cipherText;
int outputLen;
BufferedBlockCipher cipher = new BufferedBlockCipher(new AESEngine());
input = HexString.hexToBytes(inputString);
cipher.init (encrypt, new KeyParameter (HexString.hexToBytes(keyString)));
cipherText = new byte[cipher.getOutputSize(input.length)];
outputLen = cipher.processBytes( input, 0, input.length, cipherText, 0);
try {
cipher.doFinal (cipherText, outputLen);
} catch (DataLengthException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidCipherTextException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return HexString.bytesToHex(cipherText);
}
此输出方法如下:
screet:6a7573742074657374696e6700000000
key:6f2ca4106748c1eaeff88bdad4049285
结果: f1ecd6bc3109b1f2355be3a32dd49874
这是我在 IOS 上的代码:
NSLog( @"Screet : %@", secret );
NSLog( @"Key : %@", key );
NSString *encryptedString = [secret AES256EncryptWithKey:key];
NSLog( @"Result : %@", encryptedString );
NSLog( @"Result Hex : %@", [NSString stringToHex:encryptedString] );
Screet:6a7573742074657374696e6700000000
密钥:6f2ca4106748c1eaeff88bdad4049285
结果: UBXp6lFnM+XAZvVeOuYkI/T4+brXyGBmzGOUMO+XrGS8MWGDVb0RrZGBHyw2l2Ml
结果十六进制: 55425870366c466e4d2b58415a7656654f75596b492f54342b6272587947426d 7a474f554d4f2b58724753384d57474456623052725a4742487977326c324d6c
我使用这个论坛的 NSData+AESCrpt 。 有没有建议为了结果是相同的ios和java(字符串上的32字节)? 感谢各位大师的帮助:)。
Dear Gurus,
I have code on java with bouncy castle lib, like this :
private static String AES (boolean encrypt, String inputString, String keyString) {
byte [] input, cipherText;
int outputLen;
BufferedBlockCipher cipher = new BufferedBlockCipher(new AESEngine());
input = HexString.hexToBytes(inputString);
cipher.init (encrypt, new KeyParameter (HexString.hexToBytes(keyString)));
cipherText = new byte[cipher.getOutputSize(input.length)];
outputLen = cipher.processBytes( input, 0, input.length, cipherText, 0);
try {
cipher.doFinal (cipherText, outputLen);
} catch (DataLengthException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidCipherTextException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return HexString.bytesToHex(cipherText);
}
this output methode like this :
screet : 6a7573742074657374696e6700000000
key : 6f2ca4106748c1eaeff88bdad4049285
Result : f1ecd6bc3109b1f2355be3a32dd49874
and this is my code on IOS :
NSLog( @"Screet : %@", secret );
NSLog( @"Key : %@", key );
NSString *encryptedString = [secret AES256EncryptWithKey:key];
NSLog( @"Result : %@", encryptedString );
NSLog( @"Result Hex : %@", [NSString stringToHex:encryptedString] );
Screet : 6a7573742074657374696e6700000000
Key : 6f2ca4106748c1eaeff88bdad4049285
Result : UBXp6lFnM+XAZvVeOuYkI/T4+brXyGBmzGOUMO+XrGS8MWGDVb0RrZGBHyw2l2Ml
Result Hex : 55425870366c466e4d2b58415a7656654f75596b492f54342b6272587947426d7a474f554d4f2b58724753384d57474456623052725a4742487977326c324d6c
I use NSData+AESCrpt from this forum.
is there any suggestion that in order the result is same ios and java (32 Byte on String) ?
Thanks for gurus help :).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论