android RSA和Java RSA加密不一致的坑

最近项目采用RSA进行加密,遇到了坑,记录一下

1、BASE64Decoder在Android中是不存在的,需用Base64替换,
BASE64Decoder base64Decoder= new BASE64Decoder();
byte[] buffer= base64Decoder.decodeBuffer(privateKeyStr);
替换为:
byte[] buffer= Base64.decode(DEFAULT_PUBLIC_KEY, Base64.DEFAULT);

导包

import android.util.Base64;
2、cipher= Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
做加密,但是一直无法与服务器那边对接,而且每次生成的密文是一样的。
后来参考文章:http://my.oschina.net/oschenxiaomo/blog/543199
使用cipher= Cipher.getInstance("RSA/ECB/PKCS1Padding")后就可以了。

猜你喜欢

转载自blog.csdn.net/villa_mou/article/details/78811384