Permalink
Browse files

[fix] Crypto.RSA: work on binary data

  • Loading branch information...
1 parent 7cf08f9 commit 211800543665107d1e4372093551e55be09fe6f6 @Aqua-Ye Aqua-Ye committed Dec 7, 2012
Showing with 12 additions and 10 deletions.
  1. +8 −6 lib/plugins/crypto/bslCrypto.nodejs
  2. +4 −4 lib/stdlib/crypto/crypto.opa
@@ -127,19 +127,21 @@ function rsa_new_key(size) {
}
/**
- * @register {Crypto.RSA.key, string -> option(string)}
+ * @register {Crypto.RSA.key, binary -> option(binary)}
*/
function rsa_encrypt(key, msg) {
try {
- return js_some(key.encrypt(msg));
- } catch(e) { return js_none }
+ var res = key.encrypt(buffer_of_binary(msg));
+ return binary_of_buffer(new Buffer(res));
+ } catch(e) { return null }
}
/**
- * @register {Crypto.RSA.key, string -> option(string)}
+ * @register {Crypto.RSA.key, binary -> option(binary)}
*/
function rsa_decrypt(key, msg) {
try {
- return js_some(key.decrypt(msg));
- } catch(e) { return js_none }
+ var res = key.decrypt(buffer_of_binary(msg));
+ return binary_of_buffer(new Buffer(res));
+ } catch(e) { return null }
}
@@ -259,15 +259,15 @@ Crypto = {{
new_key = %% BslCrypto.rsa_new_key %% : int -> Crypto.RSA.key
/**
- * Encrypt a string with a certain RSA key.
+ * Encrypt a binary data with a certain RSA key.
*/
- encrypt = %% BslCrypto.rsa_encrypt %% : Crypto.RSA.key, string -> option(string)
+ encrypt = %% BslCrypto.rsa_encrypt %% : Crypto.RSA.key, binary -> option(binary)
/**
- * Decrypt an RSA encrypted message.
+ * Decrypt an RSA encrypted binary message.
* /!\ You might need to trim the result in order to retrieve the origin message.
*/
- decrypt = %% BslCrypto.rsa_decrypt %% : Crypto.RSA.key, string -> option(string)
+ decrypt = %% BslCrypto.rsa_decrypt %% : Crypto.RSA.key, binary -> option(binary)
}}

0 comments on commit 2118005

Please sign in to comment.