所以这是我的解密功能:
def decrypt(value):
key = b'1111111111111111'
cipher = AES.new(key, AES.MODE_ECB)
msg = cipher.decrypt(base64.b64decode(value))
return msg
而且我认为我在这里遗漏了一些东西,因为当我给它一个字符串来解密它时,它还会添加一些奇怪的字符:
例子 :hey\r\r\r\r\r\r\r\r\r\r\r\r\r
我究竟做错了什么?
PS我正在使用谷歌应用引擎和这个库from Crypto.Cipher import AES
编辑 :
private static final String ALGO = "AES";
private static final byte[] keyValue = new byte[] { '1', '1', '1', '1', '1', '1', '1', '1', '1','1', '1', '1','1','1','1','1' };
public static String encrypt(String Data) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encVal = c.doFinal(Data.getBytes());
// String encryptedValue = new BASE64Encoder().encode(encVal);
byte[] decoded = Base64.encodeBase64(encVal);
return (new String(decoded, "UTF-8") + "\n");
}
private static Key generateKey() throws Exception {
Key key = new SecretKeySpec(keyValue, ALGO);
return key;
}