Skip to content

Instantly share code, notes, and snippets.

@edewit
Last active December 28, 2015 07:49
Show Gist options
  • Save edewit/7466859 to your computer and use it in GitHub Desktop.
Save edewit/7466859 to your computer and use it in GitHub Desktop.
//Password based key derivation support (PBKDF2)
AeroGear.Crypto().deriveKey( function(password) {
console.log(password);
}, errorHandler, PASSWORD );
//Symmetric encryption support (GCM)
//Encryption:
var agCrypto = new AeroGear.Crypto();
agCrypto.deriveKey( function(rawPassword) {
var options = {
IV: "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37",
AAD: "feedfacedeadbeeffeedfacedeadbeefabaddad2",
key: rawPassword,
data: "My Bonnie lies over the ocean, my Bonnie lies over the sea"
};
agCrypto.encrypt( function(cipherText) {
console.log(cipherText)
}, options );
}, errorHandler, 'myPassword' );
//Decryption:
var options = {
IV: "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37",
AAD: "feedfacedeadbeeffeedfacedeadbeefabaddad2",
key: rawPassword,
data: cipherText
};
agCrypto.decrypt( function(text) {
console.log(text)
}, options );
//Asymmetric encryption support (ECC) / iOS not supported
agCrypto.KeyPair(function(keyPair) {
agCrypto.KeyPair(function(keyPairPandora) {
var options = {
IV: "69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37",
AAD: "feedfacedeadbeeffeedfacedeadbeefabaddad2",
key: new agCrypto.KeyPair(keyPair.privateKey, keyPairPandora.publicKey),
data: "My bonnie lies over the ocean"
};
agCrypto.encrypt(function (cipherText) {
options.key = new agCrypto.KeyPair(keyPairPandora.privateKey, keyPair.publicKey);
options.data = cipherText;
agCrypto.decrypt(function (plainText) {
console.log(plainText);
}, options);
}, options);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment