I’ve been automating a login that encrypts the password on the client with the WebCrypto API before it is sent out.
Specifically, it’s using RSA-OAEP and basically follows the examples from the MDN github:
let key = window.crypto.subtle.importKey(
"spki", binaryDer,
{ name: "RSA-OAEP", hash: "SHA-256" },
true, ["encrypt"]
);
let ciphertext = window.crypto.subtle.encrypt(
{ name: "RSA-OAEP" },
key, cleartext
);
I would have liked to do this in perl, but Crypt::OpenSSL::RSA
only supports
EME-OAEP padding as defined in PKCS #1 v2.0 with SHA-1, MGF1
…and I neither see a way to change the hash function for the padding, nor did I find another module for the job.
So I had to resort to calling the openssl
binary and encrypt the password like so:
openssl pkeyutl -in cleartext.txt -encrypt -pubin -inkey key.pem
-pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256
-pkeyopt rsa_mgf1_md:sha256
This works, however I was wondering if there is a way to achieve this with perl only.
4