I'm consuming a service developed in Java in an AngularJS application. This service returns me the bytes of an RSA public key. I need to mount the key through the bytes in JavaScript. In summary I need to do in JavaScript what is being done in Java as below:
public static PublicKey loadPublicKey(String stored){
byte[] data = Base64.decode(stored);
X509EncodedKeySpec spec = new X509EncodedKeySpec(data);
KeyFactory fact = KeyFactory.getInstance("RSA");
return fact.generatePublic(spec);
}
Can anybody help me?
You can use standard javascript WebCryptographyApi to import the public key for encryption or verify a signature. You need to set the algorithm and allowed operations depending on the expected key usage.
Encryption
Verify a signature
Utility functions
See more examples here