Introduction: RSA encryption for javascript
  • Background: cer and PFX files generated by Java program, 1024bit
  • Code: encrypt code
  • Key format conversion (emphasis) :
  1. The cer file is converted to a PEM file
openssl x509 -in public.cer -inform DER -out key.pem -outform PEM
Copy the code
  1. Extract the public key from the PEM file
openssl x509 -outform PEM -in key.pem -pubkey -out pem.pubkey
Copy the code
  1. To encrypt, open pem.pubkey and replace the public key in the HTML file
  • Summary: The PEM file is a base64 code file, so you need to extract the public key for encryption.
  • If there is anything wrong, please leave a message, thank you