Skip to content

Instantly share code, notes, and snippets.

@jondeandres
Created June 6, 2017 15:28
Show Gist options
  • Save jondeandres/72bf9ffb89569aff6feed83f910ec513 to your computer and use it in GitHub Desktop.
Save jondeandres/72bf9ffb89569aff6feed83f910ec513 to your computer and use it in GitHub Desktop.
from Cryptodome.Cipher import AES
KEY = '30c732878042aa2ea569efc1c42ab17d'
def gcm_decrypt(key, encrypted_data):
nonce, tag, ciphertext = encrypted_data[:16], encrypted_data[16:32], encrypted_data[32:]
cipher = AES.new(key, AES.MODE_GCM, nonce)
return cipher.decrypt_and_verify(ciphertext, tag)
if __name__ == '__main__':
data = raw_input()
print gcm_decrypt(KEY, data)
var fs = require('fs');
var crypto = require('crypto'),
algorithm = 'aes-256-gcm',
key = '30c732878042aa2ea569efc1c42ab17d';
function encrypt(text, key) {
var encoding = 'binary';
var tag;
var output;
crypto.pseudoRandomBytes(16, function (err, iv) {
var cipher = crypto.createCipheriv(algorithm, key, iv)
var encrypted = cipher.update(text, 'utf8', encoding)
encrypted += cipher.final(encoding);
tag = cipher.getAuthTag();
output = iv.toString('binary') + tag.toString('binary') + encrypted.toString('binary');
process.stdout.write(output.toString('binary'));
fs.writeFileSync('data', output, {
encoding: 'binary'
});
});
}
encrypt('this is the text!!', key);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment