mpetersen / aes-example Goto Github PK
View Code? Open in Web Editor NEWLearn how to build AES encryption which interoperates between Java and JavaScript
License: MIT License
Learn how to build AES encryption which interoperates between Java and JavaScript
License: MIT License
Hi,
Thank you for nice example,
I followed as per your instructions but, getting error in this line
var ciphertext = encrypted.ciphertext.toString(CryptoJS.enc.Base64);
getting error as
Property 'ciphertext' does not exist on type 'WordArray'.
Please help me to solve this issue.
Java Code:
String key = "abcdefghijklmop";
String clean = "helloworld";
String salt = AesUtil.random(16);
String iv = AesUtil.random(16);
System.out.println("Salt: " + salt);
System.out.println("IV: " + iv);
AesUtil aes = new AesUtil(128, 1000);
String encrypt = aes.encrypt(salt, iv, key, clean);
System.out.println("Encrypt: " + encrypt);
String decrypt = aes.decrypt(salt, iv, key, encrypt);
System.out.println("Decrypt: " + decrypt);
Java output: (Random newline after encrypt...)
Salt: 0d79ffd760b780829c871867a26443c1
IV: 261a6cc58ec82bf7bce99b424e0458dc
� T��ƹ&�[���?5 //KEY OUTPUT ADDED TO ENCRYPTION METHOD new String(key, "UTF-8")
Encrypt: dlRWkbQdSn8WxP9qNO/g9A==
Decrypt: helloworld
Javascript Code:
var salt = "0d79ffd760b780829c871867a26443c1"
var iv = "261a6cc58ec82bf7bce99b424e0458dc"
var pass = "abcdefghijklmop"
var encode = "dlRWkbQdSn8WxP9qNO/g9A=="
var aesUtil = new AesUtil(128, 1000);
var plain = aesUtil.encrypt(salt, iv, pass, encode);
console.log(plain)
I replaced the CryptoJS.enc.Hex.parse(salt) to salt and same with iv because I dont want hex from hex...
So it should work, should'nt it?
Output:
0eEEBBiU0g0wvrhQvvwS3z9CeYMHdLee5gu5vMcXlP0=
Does not work for me, did I any mistakes? Can you help me?
It would be great to have a 256-bit version as well, thank you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.