Я пытаюсь создать закрытый ключ RSA из строки, но он не работает и выдает ошибку java.lang.RuntimeException: Stub !. при декодировании строки в BASE64
private final static String PRIVATE_KEY =
"MIICWwIBAAKBgQCK5Z7xIyA1jv4wcJSZN3J6lpd+5G1necNAfaCyigZE0dbR0EqE\n" +
"Gk+GEMYbg2IFqI6aOrzGBbJNdTXBTSuzouIc2+KP5lxVygxXB9NP+NnB1LeNKWTK\n" +
"J8MWfJ4mSi3qJWE2Zx2qatB8iQCpZZxSBepPeYShF6tMTljBIlqFHCym/QIDAQAB\n" +
"AoGAGa4svd7FtMFUY/ZcsxtaUioHppFrXOdZX1Ia5Qe58v1tH2vIazZGH754MlwP\n" +
"QoaQnxlfD6m79rBGGRBAlTz3WyKod4O8jKMn7F7OFvsRLijJBRAQszXUoM+K7Xkf\n" +
"eL/4ikcJfp0xQ/gg6slW8bKWAqyqSlCSNyUgAHeitfWnbuECQQDLvH4gRM/RRUNV\n" +
"IVRh7bjMtOrvZ94JVj4NnbiqBNxrGk1uMhVBOEPxVskZjTO62XWSsAHC57uAkgLx\n" +
"rSj5noRFAkEArocVIPWQVJXRZ/qvvTOL6nhxZkE4oYCro9jAMLGUyQ9ca8te72mW\n" +
"8FZh+Kdsr4LphYo2Wi61WM/xIsWJwygvWQJAMOjWSn7aeP2stWIj9MJx68q+36xK\n" +
"tGkcyn4Dl+VE2P1ee0bQrXCJdwWDj3vDYGbV/9n7AkRJUgs7Y7NTM+GnFQJAZJzB\n" +
"JHgMVYbs6qmNKGCP94KptQ5CbHB2AoXQ/gFRybsOR6I9P326oyDZZ/R05pVstCxi\n" +
"ewjUSLfPxoDkk1oWOQJAe9wkFPvb677xj3uHhEa+f0PjrvwlxmR4uYW6UYuLkIcB\n" +
"erBUKxItWx/hxONXjW6tcPHQEsxgj94Gdrdnld5G0Q==";
public static void testRsaString() throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
// Read in the key into a String
StringBuilder pkcs8Lines = new StringBuilder();
BufferedReader rdr = new BufferedReader(new StringReader(PRIVATE_KEY));
String line;
while ((line = rdr.readLine()) != null) {
pkcs8Lines.append(line);
}
String pkcs8Pem = pkcs8Lines.toString();
// Base64 decode the result
byte [] pkcs8EncodedBytes = Base64.decode(pkcs8Pem, Base64.DEFAULT);
// extract the private key
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pkcs8EncodedBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
PrivateKey privKey = kf.generatePrivate(keySpec);
System.out.println(privKey);
}
}