我查看了获取私钥的代码。每个人都按照我的方式使用它。但是我收到了一个错误。可能是什么原因?我不明白。我没有得到“\ n”的标志。这可能是他的原因吗?
注意:我不能使用第三方产品。
public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
byte[] keyBytes = DatatypeConverter.parseBase64Binary("MIIEowIBAAKCAQEAz....it continues this way");
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
keyFactory.generatePrivate(spec);
}
我使用此网页http://travistidwell.com/jsencrypt/demo/获取私钥。 所有私钥(单行)。
MIIEowIBAAKCAQEAzGLFRNXk3vdcNzcSCs9AFw/Bsqis29XZB4YLyJEc1mWEWR4399v9h7PNILPLYr37bF2CwoOvT2LtFxemHiSVq53YFmjgF4TaXMDEFHC0WhhQdKirbBq23ncjUz45/XWFdZC9Xr9nkF5GkmhLLP7H6QAtdapewtp9PXMQ3n1b/ThJGua6lZWa5yWzbsj3HtTsm6uWgp1c+F7fnYEpFMgjWli4RbiwD0BcKuSrz8yMo342wH5SjFPC8p1iyYd3Q8JAeFhgxS+XvEoQMV4xg5UQpdmbC2CM3eQKgHs/iBIUsiDtIK8brB4MM1OIdJxAUWXg6wMqViG7NWblcBRZ2X7L6QIDAQABAoIBADbs5C6XfKYeu31rI0IcaBDKfzdP9QQu99/5ufjwZluHdIWuhUPqrrtlKl77clDa1VJN3vH/CYHACA8In+/BzScNiCCdlns7jKMYepkzoIQFvLldCpRGqZYnVirsshDXIEJz3zAzJ9W4QCbgODOjVH3dOlpAqq6aoMV+wq3H6oyltKOu4cinQhCii+Df8rdwFuHzTdCxJScHo8+vrO33Zqo7/Y0QG84eK9zSQgGX1yWvkUEkOduuyMPHJb/pdkKjNi1a8X19qmsRydFE2LB0Ci8wZxJJhO1Dx3yX8sxCYuvQ+o3+MEnhpvdesiwnSEYblCpAGdgiP+/POYH2zYT3egECgYEA6sA7fPIknni6PkRvsVo6vdGHYyOSLtEoSwAXpIXDvqJaRal6JRiNTgyar1WOv/e4FuWt+SvpNTdKkw0dt/MgCkPteJlnTU/qDFRcW/TYp/zVB4IsbQ2SmOw1LFsrRT479qjJRcWedwqS51fgjlJlP2CSyFC1gk0KVsxwrgZeBFECgYEA3uLnKf4+iYs/1/UXz3Ujp8D7Nr5ak2BMHCdy/GyIt0HAlmkc+2+5A9d/yOhV+dNFab4+mepvuMcgq7OWQK4L9eQqRQSMdreMxYxxCB9TMPiikupZwPGBzpnr9p/jvaESgwNP2oz9RhIrTD3LgPZIhRUpkHkutPQAjp83TTsSYBkCgYALux196e/Qh4HvGKZoO3USBUV5u85TTppv3QpRa2nTvfM65fQ3pFlzXAfi2SiwCSYG5uVhvUMDKMcuQAqLJbglKy3Tx/60i1jL0u9mnP6yrlzK6kNkE7iOsccad1fbNvfyJI8iUHTRyBJ9QxPyqMVsfFv5bKcVYtowajj7SVArcQKBgCBgdZP0CsGQKMYGJF9OdM95iQR6wk2GP4gXcuyYF4QHWSKAQmWD5SxZsYZNua+AsSSbLhzNoU0GIAjRHZJntfUSH9HGx2C3aQuJSyIS6tLCS1tsD32nl2ObmFtK/podO8MsR/1HXcNAAGoiz9z76azrVg5WjCJdD3eoSTA+1HyBAoGBAKKLLbglTwNXhXbwGpTa7qHsuVkH9cPOJcXE/AfbUTczLfm6KzvNXee1bSKvbZ27nfknjH9Yp8mBSsubKiX4MC/C4snLK/1nd7Awe0XM/yO5c9zc00I/gXzxu1dLnSoasDqjdWn21hy1zdubX2VBL9B4pkWRbNCOxVn8PBqfHXM/
错误代码;
Exception in thread "main" java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException : algid parse error, not a sequence at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:217)
at java.security.KeyFactory.generatePrivate(KeyFactory.java:372)
at Main.main(Main.java:23)
Caused by: java.security.InvalidKeyException: IOException : algid parse error, not a sequence
at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:351)
at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:356)
at sun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:91)
at sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:75)
at sun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:316)
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:213)
... 2 more