<!---->
<!doctype html>
<html>
<head>
<title>GP LD LK</title>
<script type="text/javascript">
//init jsencryp
var encrypt = new JSEncrypt();
//add publib key provided byu greenpay with no \n
encrypt.setPublicKey("MIGfMA0GCSqGSIb3DQEBA....QUAA4GNADCBiQKBg");
$(function() {
// cardDataObject is the object that must be encrypted when you are going to create a token
var cardDataObject = {
"card":{
"cardHolder": "Tico payment user", //must have more tha 5 chars
"expirationDate": {
"month": 12,
"year": 23
},
"cardNumber": "4242424242424242",
"cvc": "123",
"nickname": "nickname" //more than 5 chars and less tan 50 chars
}
};
// encrypt the card data and print the log in console
var cardDataEcrypted = pack(cardDataObject, undefined);
console.log('Card data encrypted:', JSON.stringify(cardDataEcrypted));
});
function pack(obj, pair_) {
var pair = (pair_ !== undefined) ? pair_ : this.generateAESPairs();
var textBytes = aesjs.utils.utf8.toBytes(JSON.stringify(obj));
var aesCtr = new aesjs.ModeOfOperation.ctr(pair.k, new aesjs.Counter(pair.s));
var encryptedBytes = aesCtr.encrypt(textBytes);
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);
var returnObj = {
ld:encryptedHex,
lk:encrypt.encrypt(JSON.stringify(pair))
};
return returnObj;
}
function generateAESPairs () {
var key = []
var iv = 0;
for (var k = 0; k < 16; k++) {
key.push(Math.floor(Math.random() * 255))
}
for (var k = 0; k < 16; k++) {
iv = Math.floor(Math.random() * 255)
}
return {
k: key,
s: iv
}
}
</script>
</head>
<body>
</body>
</html>