can someone please help me with this aes encryption js
idk how to create ob blocks with it
(function() {
'use strict';
// Generatized Encryption Factory
angular.module('pharmacyCaregiver').service('encryption', [function() {
var AesUtil = function(keySize, iterationCount) {
this.keySize = keySize / 32;
this.iterationCount = iterationCount;
};
var config = {};
config.encryption = {
isEncrypted: true,
symmetricKey: "keytouse12345",
salt: "3FF2EC019C627B945225DEBAD71A01B6985FE84C95A70EB132882F88C0A59A55",
iv: "F27D5C9927726BCEFE7510B1BDD3D137",
passPhrase: "YTI1NjllYmEtN2VhYS00Yj"
};
AesUtil.prototype.generateKey = function(salt, passPhrase) {
var key = CryptoJS.PBKDF2(passPhrase, CryptoJS.enc.Hex.parse(salt), {
keySize: this.keySize,
iterations: this.iterationCount
});
return key;
};
AesUtil.prototype.aesEncryption = function(plainText) {
if (config.encryption.isEncrypted) {
var key = this.generateKey(config.encryption.salt, config.encryption.passPhrase);
var encrypted = CryptoJS.AES.encrypt(plainText, key, {
iv: CryptoJS.enc.Hex.parse(config.encryption.iv)
});
return encrypted.ciphertext.toString(CryptoJS.enc.Base64);
} else {
return plainText;
}
};
AesUtil.prototype.aesDecryption = function(cipherText) {
if (config.encryption.isEncrypted) {
var key = this.generateKey(config.encryption.salt, config.encryption.passPhrase);
var cipherParams = CryptoJS.lib.CipherParams.create({
ciphertext: CryptoJS.enc.Base64.parse(cipherText)
});
var decrypted = CryptoJS.AES.decrypt(cipherParams, key, {
iv: CryptoJS.enc.Hex.parse(config.encryption.iv)
});
return decrypted.toString(CryptoJS.enc.Utf8);
} else {
return cipherText;
}
};
return new AesUtil(128, 2);
}]);
})();