本帖最后由 tangzhen0552 于 2014-05-14 09:16:41 编辑

解决方案 »

  1.   

         var window = window || {};
         (function w() {
             if (typeof RSAUtils === 'undefined')/////////这里多了个空格
                 var RSAUtils = window.RSAUtils = {}; //做成全局变量,要不只能在w内部访问
             var RSAKeyPair = function (encryptionExponent, decryptionExponent, modulus) {
                 var dmath = RSAUtils;
                 this.e = dmath.biFromHex(encryptionExponent);
                 this.d = dmath.biFromHex(decryptionExponent);
                 this.m = dmath.biFromHex(modulus);
                 this.chunkSize = 2 * dmath.biHighIndex(this.m);
                 this.radix = 16;
                 this.barrett = new BarrettMu(this.m);
             };
             RSAUtils.getKeyPair = function (encryptionExponent, decryptionExponent, modulus) {
                 return new RSAKeyPair(encryptionExponent, decryptionExponent, modulus);
             };
             RSAUtils.encryptedString = function (key, s) {
                 var a = [];
                 var sl = s.length;
                 var i = 0;
                 while (i < sl) {
                     a = s.charCodeAt(i);
                     i++;
                 }
                 while (a.length % key.chunkSize != 0) {
                     a[i++] = 0;
                 }
                 var al = a.length;
                 var result = "";
                 var j, k, block;
                 for (i = 0; i < al; i += key.chunkSize) {
                     block = new BigInt();
                     j = 0;
                     for (k = i; k < i + key.chunkSize; ++j) {
                         block.digits[j] = a[k++];
                         block.digits[j] += a[k++] << 8;
                     }
                     var crypt = key.barrett.powMod(block, key.e);
                     var text = key.radix == 16 ? RSAUtils.biToHex(crypt) : RSAUtils.biToString(crypt, key.radix);
                     result += text + " ";
                 }
                 return result.substring(0, result.length - 1); // Remove last space.
             };
             //RSAUtils.setMaxDigits(130);//////你的这个方法也没定义,不知道你在其他地方定义过没有
         })(window);
         RSAUtils.getKeyPair()
         RSAUtils.encryptedString()
      

  2.   

    if (typeof RSAUtils === ' undefined') //多了空格,而且总会是true
    var RSAUtils = RSAUtils = {}; 
    这两条语句相当于
    var RSAUtils;
    if(typeof RSAUtils === 'undefined')
        RSAUtils=window.RSAUtils={}在RSAUtils.setMaxDigits (130);语句后添加
    window.RSAUtils=RSAUtils试试