Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encryption Decryption Using AES 256 in Crypto.js Format Needed #16

Open
RohanGau opened this issue Feb 1, 2023 · 0 comments
Open

Encryption Decryption Using AES 256 in Crypto.js Format Needed #16

RohanGau opened this issue Feb 1, 2023 · 0 comments

Comments

@RohanGau
Copy link

RohanGau commented Feb 1, 2023

Need encryption decryption format written on crypto.js methodology for frontend use.

  • we have a sample of java how we will encrypt web redirection essential values in ASE 256 algo but we need a javascript
    description where we can identify how will we do a code in same format using ASE 256 with given keys as mention on
    below.

  • Facing a issue while we generate secretkey using salt and key in JS so aeed a javascript code using crypto.js lib will help
    us to encrypt or decrypt value similar format as backend on frontend-side.

  • We are using same value as mention on doc:

    IV – This can be 0
    SALT – This will be the reqdate or resdate
    FI – This will be the unique FIU ID ( i.e. the FIU entity id )
    SECRETKEY – This will be the secret passphrase shared by the AA with the FIU.
    
  • Sample of JS code what we have designed

// generate secret key using key and salt
const getSecretKey = () => {
  var secretkey = redirectionSecretKey;
  var saltKey = "abcde";
  var key = CryptoJS.enc.Utf8.parse(secretkey);
  var salt = CryptoJS.enc.Utf8.parse(saltKey);
   const generateKey = CryptoJS.PBKDF2(key, salt, {
      keySize: 256,
       iterations: 1000,
   });
 return generateKey;
};

// generate IV
const getIv = () => {
 var iv2 = CryptoJS.lib.WordArray.create([
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 ]);
 return iv2;
};

// Encryption method
export const encodeDataInASE2 = (data) => {
 var encrypted = CryptoJS.AES.encrypt(
   data,
   getSecretKey2(),
   {
     iv: getIv2(),
     mode: CryptoJS.mode.CBC,
     padding: CryptoJS.pad.Pkcs7,
   }
 ).toString();

 return encrypted;
};

// Decryption method
export const decodeDataFromASE = (ciphertext) => {
 const decryptCiphertext = CryptoJS.AES.decrypt(ciphertext, getSecretKey(), {
   iv: getIv(),
   mode: CryptoJS.mode.CBC,
   padding: CryptoJS.pad.Pkcs7,
 });
 const decryptedData = JSON.parse(
   decryptCiphertext.toString(CryptoJS.enc.Utf8)
 );

 return decryptedData;
};
@RohanGau RohanGau changed the title Encryption Decryption Using AES 256 in Crypto.js Format Need Encryption Decryption Using AES 256 in Crypto.js Format Needed Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant