因此,我有一个Android应用程序和一个用python编写的谷歌应用程序引擎服务器。 Android应用程序需要发送一些合理的信息到服务器,我这样做的方式是做一个http发布。Android中的安全 - 谷歌应用程序引擎系统
现在我一直在考虑在发送它之前对android中的数据进行加密,并且一旦它在gae服务器上进行解密。
我这是怎么加密和Java中解密:
private static final String ALGO = "AES";
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");
}
public static String decrypt(String encryptedData) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.DECRYPT_MODE, key);
byte[] decordedValue =Base64.decodeBase64(encryptedData);
byte[] decValue = c.doFinal(decordedValue);
String decryptedValue = new String(decValue);
return decryptedValue;
}
private static Key generateKey() throws Exception {
Key key = new SecretKeySpec(Constant.keyValue, ALGO);
return key;
}
而且这是我尝试解密的服务器上(我还不知道怎么办encryption..maybe你们可以与太帮助)
def decrypt(value):
key = b'1234567891234567'
cipher = AES.new(key, AES.MODE_ECB)
msg = cipher.decrypt(value)
return msg
正如我在日志中望去,串测试,我得到的是:xVF79DzOplxBTMCwAx+hoeDJhyhifPZEoACQJcFhrXA=
因为它不是16的倍数(IDK为什么,我想这是因为Java加密)我得到错误
ValueError:输入字符串必须是长度为16的倍数
我在做什么错?
你为什么不使用SSL(HTTPS又名)?这应该提供在手机和App Engine之间安全且私密地传输数据所需的所有加密。 –
@Fh。任何教程/资源,我会看到如何做到这一点?我是一种newby :) – Teshte
更长的答案添加为答案:) –