The PublicKey.getEncoded(), returns a byte array containing the public key in SubjectPublicKeyInfo (x.509) format, how do i convert it to RSA public key encoding?
Use Bouncy Castle's SubjectPublicKeyInfo, like this:
SubjectPublicKeyInfo
byte[] encoded = publicKey.getEncoded(); SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance( ASN1Sequence.getInstance(encoded)); byte[] otherEncoded = subjectPublicKeyInfo.parsePublicKey().getEncoded();
1.4m articles
1.4m replys
5 comments
57.0k users