Я пытаюсь расшифровать qr-код, зашифрованный rsa, но продолжаю получать следующую ошибку:
com. android .org.conscrypt.opensslx509certificatefactory $ parsingexception
мой код выглядит следующим образом :
private static String privateKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKBAA2dMO/OfCxLfScyBs1YyWR6xSGPX/qf9P5+RzIu2vBG7pZiY2Yx05uHTFLs8YIZ6nuULbKq+C2x+S3SyCacCAwEAAQ==";
try {
PrivateKey PK = getPrivateKey(privateKey);
String str = intentData;
byte[] byteArr = str.getBytes();
txtBarcodeValue.setText(decrypt(byteArr,PK));
} catch (Exception e) {
txtBarcodeValue.setText(e.getMessage());
}
private PrivateKey getPrivateKey(String PRIVATE_KEY) throws Exception {
String pkcs8Pem = PRIVATE_KEY;
byte [] pkcs8EncodedBytes = Base64.decode(pkcs8Pem, Base64.DEFAULT);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pkcs8EncodedBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
PrivateKey privKey = kf.generatePrivate(keySpec);
return privKey;
}
private static String decrypt(byte[] buffer,PrivateKey privateKey) {
try {
Cipher rsa;
rsa = Cipher.getInstance("RSA");
rsa.init(Cipher.DECRYPT_MODE, privateKey);
byte[] utf8 = rsa.doFinal(buffer);
return new String(utf8, "UTF8");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}