cpay-enc-dec
v1.0.6
Published
cpay encrpt and decrpt text through rsa ssl certificate files or text.
Downloads
2
Readme
CPay encryption and decryption through RSA certificate key files or text.
The following methods for RSA encryption and decryption :
cPayGetEncryptionDataFromKeyFile(input_data, key_filepath, calback);
cPayGetEncryptionDataFromKeyText(input_data, key_txt, calback);
cPayGetDecryptionDataFromKeyFile(input_data, key_filepath, calback);
cPayGetDecryptionDataFromKeyText(input_data, key_txt, calback);
Example Code:
var cpayEncDec = require('cpay-enc-dec');
var json = {
"name" : "cpay"
}
var enc_rslts: any;
// convert json/string data to rsa encrypted format with public key file
cpayEncDec.cPayGetEncryptionDataFromKeyFile(json, '/certificates/public.key', (encrpt_err, encrpt_res)=>{
if(encrpt_err){
console.log(encrpt_res);
//with error do something
}
else{
console.log(encrpt_res);
enc_rslts = encrpt_res;
//with encrypted data do something
}
})
// convert rsa encrypted data to decrypted json/string data format with private key file
cpayEncDec.cPayGetDecryptionDataFromKeyFile(enc_rslts, '/certificates/private.key', (dcrpt_err, dcrpt_res)=>{
if(dcrpt_err){
console.log(dcrpt_res);
//with error do something
}
else{
console.log(dcrpt_res);
//with decrypted data do something
}
})
var public_key_txt = "IgUMIRSetSr2XU+E5lUvYe2y0yEgHjAkb82++B1G/yw6o0YCsnNg8GhQbSHKTHLanJvdLYv5W5kmFCdQCWyFtmc45MeT1MTwkPUav1xhSzEu5UcErONggQLIhDnAjRNuxbo5p4Hvw3R/zOgnNtE";
var pvt_key_txt = "MIIJKAIBAAKCAgEAwnja95l9qwlMgj1yyXVf1AemEx1tY4cLRb6TnbyCedgrVkatjHUCUUJXnlMN2NdiUURWiChmb1IX/2AAVN3GWjjYoaavC2FKt7sa22Cq+KjmrLDMyrSjZKmETpv91j5nHZst7sPhbGXp9oembcl61ix41b/AP0X1gn";
// convert json/string data to rsa encrypted format with public key text
cpayEncDec.cPayGetEncryptionDataFromKeyText(json, public_key_txt, (encrpt_err, encrpt_res)=>{
if(encrpt_err){
console.log(encrpt_res);
//with error do something
}
else{
console.log(encrpt_res);
enc_rslts = encrpt_res;
//with encrypted data do something
}
})
// convert rsa encrypted data to decrypted json/string data format with private key text
cpayEncDec.cPayGetDecryptionDataFromKeyText(enc_rslts, pvt_key_txt, (dcrpt_err, dcrpt_res)=>{
if(dcrpt_err){
console.log(dcrpt_res);
//with error do something
}
else{
console.log(dcrpt_res);
//with decrypted data do something
}
})