java aes cfb 256加密

调过一个加密程序,后台用c++ openssl aes cfb 128加密的,用java写的加密程序发到后台怎么都解密不了,后改用java调jni c 的openssl加密才解决。现在发现是java这边加密写的有问题,正确的加密如下,解密类似。

public static final byte[] DEFAULT_KEY = { (byte) 0xF3, (byte) 0x62,
			(byte) 0x12, (byte) 0x05, (byte) 0x13, (byte) 0xE3, (byte) 0x89,
			(byte) 0xFF, (byte) 0x23, (byte) 0x11, (byte) 0xD7, (byte) 0x36,
			(byte) 0x01, (byte) 0x23, (byte) 0x10, (byte) 0x07, (byte) 0x05,
			(byte) 0xA2, (byte) 0x10, (byte) 0x00, (byte) 0x7A, (byte) 0xCC,
			(byte) 0x02, (byte) 0x3C, (byte) 0x39, (byte) 0x01, (byte) 0xDA,
			(byte) 0x2E, (byte) 0xCB, (byte) 0x12, (byte) 0x44, (byte) 0x8B };
private static final byte[] AES_IV = { 0x15, (byte) 0xFF, 0x01, 0x00, 0x34,
			(byte) 0xAB, 0x4C, (byte) 0xD3, 0x55, (byte) 0xFE, (byte) 0xA1,
			0x22, 0x08, 0x4F, 0x13, 0x07 };
SecretKeySpec secretKeySpec = new SecretKeySpec(DEFAULT_KEY, "AES");
IvParameterSpec paramSpec = new IvParameterSpec(AES_IV);
Cipher ecipher;
ecipher = Cipher.getInstance("AES/CFB/NOPADDING");
ecipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, paramSpec);
byte[] result = ecipher.doFinal(content.getBytes());
return result;

 另外,pc java默认的jar包不支持256加密,即32位密钥。要到官网下载jar包替换java_home/jre/lib/security下的jar包才可以。android 默认支持256位加密。

猜你喜欢

转载自zuoshu.iteye.com/blog/1821221
今日推荐