I have the encryption_key but the below code generates another public key as below.
I need help in writing the same code in Javascript. Please let me know how can I do it.
Note: I am creating an AES key(random 32 bytes) and iv(initialization vector) of 16 bytes, then use these to encrypt my payload. This AES Key & IV will be then encrypted by public key(below generated). But, I have exhausted all options to rewrite the below code in Javascript.
public static PublicKey getOtherPublicKey(String encryption_key) {
try {
byte[] publicBytes = Base64.getDecoder().decode(encryption_key);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (InvalidKeySpecException e) {
System.out.println("Invalid key specification.");
throw new IllegalArgumentException(e);
}
}