Skip to content

Instantly share code, notes, and snippets.

@abhitheawesomecoder
Created August 9, 2019 13:17
Show Gist options
  • Save abhitheawesomecoder/d805efdc2bad6327161ccd13037ad765 to your computer and use it in GitHub Desktop.
Save abhitheawesomecoder/d805efdc2bad6327161ccd13037ad765 to your computer and use it in GitHub Desktop.
var key = aesjs.utils.utf8.toBytes("j3u8ue8xmrhsth59");
// Convert text to bytes
var text = 'GLGqOsjCQejV8wvNflrKvXkNfvYYR+eqogEn8payz3MHk8VLK5Wet0Y6F6c6L5yoXvsMZ5SEwHD5boeNuc5hcdKXOMDhu31T3kLNGPxOcfL0oiv78pP4MmLeekQWvfZbbKNdsAEaXwU5VHFN4SMKNwAhAKoCOrqCKrv4V9W4odwQDOFQpmogxPD2iLMCUAVkzQZB+aqAg4r6yranT/uGvvImPe+jlOH8I28qWGCPEtCM5N+n/QiQrJ+lZHK8SJgnnBsLJdj778/0Maiqx7huyAmnHJx0vxbH+gv+zsrtrIr8x++io+genj8pabVmN1e1';
var textEnc = '{"dataId":"00058F9C9BE9A2D4BBCE67122FB80002","devId":"175540103c71bf20df5a","productKey":"66mNaBqLdsYhX5lA","status":[{"1":"true","code":"switch","t":1565277677005,"value":true},{"2":"0","code":"countdown_1","t":1565277677005,"value":0}]}';
function _base64ToBytesr(base64) {
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array( len );
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes;
}
const textbytes = _base64ToBytesr(text);
console.log(textbytes);
var aesEcb = new aesjs.ModeOfOperation.ecb(key);
var decryptedBytes = aesEcb.decrypt(textbytes);
console.log(textbytes);
var decryptedText = aesjs.utils.utf8.fromBytes(textbytes);
console.log(decryptedText);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment