Last active
April 25, 2016 21:05
-
-
Save Nakort/e54dc03cfd09a01674c0e8e0ca2b313d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
key = Base64.encode64(Random.new.bytes(32)) | |
iv = Base64.encode64(Random.new.bytes(16)) | |
// Javascript example: | |
// Encrypting | |
var key = CryptoJS.enc.Base64.parse("X/+3w9RBaEQHp3kJS/haIw8TpHgX03pUkEJoEfdDdhY=") | |
var iv = CryptoJS.enc.Base64.parse("LHYP7XXgN9KOOoiGw9M7mA==") | |
encrypted = CryptoJS.AES.encrypt("659-98-0876", key, { iv: iv, mode: CryptoJS.mode.CBC}); | |
encrypted.toString() // "yfxIZnkyIjTiDknPuRhxKQ==" | |
//Decrypting | |
var encrypted_text = "yfxIZnkyIjTiDknPuRhxKQ==" | |
var key = CryptoJS.enc.Base64.parse("X/+3w9RBaEQHp3kJS/haIw8TpHgX03pUkEJoEfdDdhY=") | |
var iv = CryptoJS.enc.Base64.parse("LHYP7XXgN9KOOoiGw9M7mA==") | |
encrypted = CryptoJS.AES.decrypt(encrypted_text, key, { iv: iv, mode: CryptoJS.mode.CBC}); | |
encrypted.toString(CryptoJS.enc.Utf8) | |
// Ruby Example | |
key = Base64.decode64("X/+3w9RBaEQHp3kJS/haIw8TpHgX03pUkEJoEfdDdhY=") | |
iv = Base64.decode64("LHYP7XXgN9KOOoiGw9M7mA==") | |
c = OpenSSL::Cipher::Cipher.new("aes-256-cbc") | |
c.encrypt | |
c.key = key | |
c.iv = iv | |
Base64.strict_encode64(c.update(ssn) << c.final) // "yfxIZnkyIjTiDknPuRhxKQ==" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment