Skip to content

Instantly share code, notes, and snippets.

@paddybyers
Forked from Honigbaum/gist:3782352
Created September 25, 2012 16:14
Show Gist options
  • Save paddybyers/3782869 to your computer and use it in GitHub Desktop.
Save paddybyers/3782869 to your computer and use it in GitHub Desktop.
Encryption
Java:
String encrypt(String inputString) {
IvParameterSpec ivSpec = new IvParameterSpec("c1234567-zipl-03".getBytes());
SecretKeySpec keySpec = new SecretKeySpec("GeN8IfCrdxKxMxFA".getBytes(), "AES");
Cipher cipher;
try {
cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
byte[] encryptedResult = cipher.doFinal(inputString.getBytes());
return "1" + bytesToHex(encryptedResult);
} catch (Throwable t) {
t.printStackTrace();
}
return null;
}
node:
function encrypt(inputString) {
var inputVector = (new Buffer("c1234567-zipl-03")).toString('binary');
var secretKeyHash = (new Buffer("GeN8IfCrdxKxMxFA")).toString('binary');
var cipher = crypto.createCipheriv('AES-128-CBC', secretKeyHash, inputVector);
return 1 + cipher.update(inputString, 'utf8', 'hex');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment