如何正确使用SDK加密串
正式使用解决方案
一、设计自己的加解密方式。
服务端Java示例:
/*该示例采用AES加密算法,开发者也可以选择使用不同的加密算法,并在APP端做对应的解密。*/
String plainString = userid + "," + secretkey + "," + readtoken + "," + writetoken;
String key = "1234567812345678"; // 加密密钥
String iv = "1234567812345678"; // 加密向量
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
int blockSize = cipher.getBlockSize();
byte[] dataBytes = plainString.getBytes();
int plaintextLength = dataBytes.length;
if (plaintextLength % blockSize != 0) {
plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
}
byte[] plaintext = new byte[plaintextLength];
System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
byte[] encrypted = cipher.doFinal(plaintext);
String baseString = Base64.encode(encrypted);
System.out.println(baseString);服务器端 PHP 加密示例:
Android 端解密和配置
iOS 端解密和配置:
二、保证服务端接口稳定
三、对APP进行加固
Last updated