我正在尝试使用RSA快速加密和解密,我想以一种对Android Cipher的微笑方式进行尝试,我尝试使用RSAUtils,但是由于我无法添加PKCS1Padding,因此它不起作用,说实话,这是第一次进行加密和解密工作,所以我对这个主题没有经验,
String publicKeyB64 = "Key";
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decodeBase64(publicKeyB64.getBytes()))));
String encrypted = Util.toBase64(cipher.doFinal(MESSAGE.getBytes()));
String privateKeyB64 = "Key";
cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(Util.decodeBase64(privateKeyB64.getBytes()))));