Skip to content

Commit

Permalink
Adding base64 encoding to the output and input.
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Feb 16, 2013
1 parent 084db95 commit 9fa2e3a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
27 changes: 22 additions & 5 deletions bin/jsencrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1795,20 +1795,37 @@ RSAPublicKey.prototype.parseKey = function(pubkey) {
/**
* Class to do the encryption.
*/
var JSEncrypt = function() {};
var JSEncrypt = function() {

// The private and public keys.
this.privkey = null;
this.pubkey = null;
};

/**
* Decryption method to take a private PEM string and decrypt text.
*/
JSEncrypt.prototype.decrypt = function(privkey, string) {
var key = new RSAPrivateKey(privkey);
return key.decrypt(string);

// If the key has already been defined, then don't define it again.
if (!this.privkey) {
this.privkey = new RSAPrivateKey(privkey);
}

// Return the decrypted string.
return this.privkey.decrypt(b64tohex(string));
}

/**
* Encrypttion method to take a public PEM string and encrypt text.
*/
JSEncrypt.prototype.encrypt = function(pubkey, string) {
var key = new RSAPublicKey(pubkey);
return key.encrypt(string);

// If the pubkey has not been defined then do it here.
if (!this.pubkey) {
this.pubkey = new RSAPublicKey(pubkey);
}

// Return the encrypted string.
return hex2b64(this.pubkey.encrypt(string));
}
3 changes: 2 additions & 1 deletion bin/jsencrypt.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/jsencrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ JSEncrypt.prototype.decrypt = function(privkey, string) {
}

// Return the decrypted string.
return this.privkey.decrypt(string);
return this.privkey.decrypt(b64tohex(string));
}

/**
Expand All @@ -184,5 +184,5 @@ JSEncrypt.prototype.encrypt = function(pubkey, string) {
}

// Return the encrypted string.
return this.pubkey.encrypt(string);
return hex2b64(this.pubkey.encrypt(string));
}

0 comments on commit 9fa2e3a

Please sign in to comment.