Skip to content

Instantly share code, notes, and snippets.

@ChunAllen
Last active August 1, 2022 05:45
Show Gist options
  • Save ChunAllen/d7d5be86c1516966bdaa7dd2b4151970 to your computer and use it in GitHub Desktop.
Save ChunAllen/d7d5be86c1516966bdaa7dd2b4151970 to your computer and use it in GitHub Desktop.
Encrypting RSAOAEP256 password
// 1) Import this forge.min.js from browser console
var script = document.createElement('script');script.src = "https://cdnjs.cloudflare.com/ajax/libs/forge/1.3.1/forge.min.js";document.getElementsByTagName('head')[0].appendChild(script);
// 2) Paste this method in browser console
function encryptPassword(psd, pem) {
try {
//using jsencrypt.js
/* var encrypt = new JSEncrypt();
encrypt.setPublicKey(publicKey);
return encrypt.encrypt(psd); */
//using forge.min.js
var pki = forge.pki;
var publicKey = pki.publicKeyFromPem(pem);
var encrypted = publicKey.encrypt(psd, 'RSA-OAEP', {
md: forge.md.sha256.create(),
mgf1: {
md: forge.md.sha1.create()
}
});
return btoa(encrypted);
} catch(e){
console.log("encryptPassword() => e =", e);
}
return "";
}
// 3) Call Get PublicKeyAPI and copy the publickey
// 4) Generate the pem variable
pem = "-----BEGIN PUBLIC KEY-----\n{publicKey}\n-----END PUBLIC KEY-----\n"
//5) Copy the encrypted password and paste it in im8_password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment