FIX REAL REAL YESSSS

This commit is contained in:
ayunami2000 2022-01-23 20:20:13 -05:00
parent 3099109d0d
commit d5caf5a313
6 changed files with 1019 additions and 1011 deletions

File diff suppressed because one or more lines are too long

View File

@ -4,11 +4,11 @@
<script type="text/javascript" src="jsbn/jsbn.js"></script>
<script type="text/javascript" src="jsbn/jsbn2.js"></script>
<script type="text/javascript" src="jsbn/base64.js"></script>
<script type="text/javascript" src="jsbn/prng4.js"></script>
<script type="text/javascript" src="jsbn/rng.js"></script>
<script type="text/javascript" src="jsbn/rsa.js"></script>
<script type="text/javascript" src="jsbn/rsa2.js"></script>
<script type="text/javascript" src="jsbn/base64.js"></script>
<script type="text/javascript" src="asn1-parser.js"></script>

View File

@ -26,13 +26,18 @@ function byte2Hex(b) {
// PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint
function pkcs1pad2(s,n) {
//var ba = b64toBA(hex2b64(s));
//n -= ba.length;
if(n < s.length + 11) { // TODO: fix for utf-8
alert("Message too long for RSA");
return null;
}
var ba = new Array();
var i = s.length - 1;
var i = (s.length / 2) - 1;
while(i >= 0 && n > 0) {
ba[--n] = parseInt(s.substring(2*i,2*i+2),16);
i--;
/*
var c = s.charCodeAt(i--);
if(c < 128) { // encode using utf-8
ba[--n] = c;
@ -46,6 +51,7 @@ function pkcs1pad2(s,n) {
ba[--n] = ((c >> 6) & 63) | 128;
ba[--n] = (c >> 12) | 224;
}
*/
}
ba[--n] = 0;
var rng = new SecureRandom();

View File

@ -14,6 +14,8 @@ function pkcs1unpad2(d,n) {
if(++i >= b.length) return null;
var ret = "";
while(++i < b.length) {
ret += byte2Hex(b[i]);
/*
var c = b[i] & 255;
if(c < 128) { // utf-8 decode
ret += String.fromCharCode(c);
@ -26,6 +28,7 @@ function pkcs1unpad2(d,n) {
ret += String.fromCharCode(((c & 15) << 12) | ((b[i+1] & 63) << 6) | (b[i+2] & 63));
i += 2;
}
*/
}
return ret;
}

View File

@ -64,10 +64,10 @@ public class CryptManager
}
///*
@JSBody(params = {"pubkey", "mod", "indata"}, script = "var rsa=new RSAKey();rsa.setPublic(b64tohex(mod),b64tohex(pubkey));var res=hex2b64(rsa.encrypt(atob(indata)));return res;")
@JSBody(params = {"pubkey", "mod", "indata"}, script = "var rsa=new RSAKey();rsa.setPublic(b64tohex(mod),b64tohex(pubkey));var res=hex2b64(rsa.encrypt(b64tohex(indata)));return res;")
private static native String encryptDataNative(String pubkey, String mod, String indata);
@JSBody(params = {"privkey", "mod", "indata"}, script = "var rsa=new RSAKey();rsa.setPrivate(b64tohex(mod),b64tohex(privkey));var res=rsa.decrypt(b64tohex(indata));return res;")
@JSBody(params = {"privkey", "mod", "indata"}, script = "var rsa=new RSAKey();rsa.setPrivate(b64tohex(mod),b64tohex(privkey));var res=hex2b64(rsa.decrypt(b64tohex(indata)));return res;")
private static native String decryptDataNative(String pubkey, String mod, String indata);
//*/