Security implemented + Partial publish
diff --git a/js/securityLib/rsa.js b/js/securityLib/rsa.js
index 6150003..11efe45 100644
--- a/js/securityLib/rsa.js
+++ b/js/securityLib/rsa.js
@@ -24,7 +24,11 @@
return b.toString(16);
}
-// PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint
+/**
+ * PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint
+ * @param s: the string to encode
+ * @param n: the size in byte
+ */
function pkcs1pad2(s,n) {
if(n < s.length + 11) { // TODO: fix for utf-8
alert("Message too long for RSA");
@@ -60,7 +64,10 @@
return new BigInteger(ba);
}
-// "empty" RSA key constructor
+/**
+ * "empty" RSA key constructor
+ * @returns {RSAKey}
+ */
function RSAKey() {
this.n = null;
this.e = 0;
@@ -72,7 +79,12 @@
this.coeff = null;
}
-// Set the public key fields N and e from hex strings
+/**
+ * Set the public key fields N and e from hex strings
+ * @param N
+ * @param E
+ * @returns {RSASetPublic}
+ */
function RSASetPublic(N,E) {
if(N != null && E != null && N.length > 0 && E.length > 0) {
this.n = parseBigInt(N,16);
@@ -82,12 +94,18 @@
alert("Invalid RSA public key");
}
-// Perform raw public operation on "x": return x^e (mod n)
+/**
+ * Perform raw public operation on "x": return x^e (mod n)
+ * @param x
+ * @returns x^e (mod n)
+ */
function RSADoPublic(x) {
return x.modPowInt(this.e, this.n);
}
-// Return the PKCS#1 RSA encryption of "text" as an even-length hex string
+/**
+ * Return the PKCS#1 RSA encryption of "text" as an even-length hex string
+ */
function RSAEncrypt(text) {
var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3);
if(m == null) return null;