@ -906,112 +906,14 @@ if (!_global.BI) {
} ,
/ * *
* 对字符串进行加密 { @ link # decrypt }
* @ static
* @ param str 原始字符 <EFBFBD> ?
* @ param keyt 密钥
* @ returns { String } 加密后的字符 <EFBFBD> ?
* /
encrypt : function ( str , keyt ) {
if ( str == "" ) {
return "" ;
}
str = escape ( str ) ;
if ( ! keyt || keyt == "" ) {
keyt = "655" ;
}
keyt = escape ( keyt ) ;
if ( keyt == null || keyt . length <= 0 ) {
alert ( "Please enter a password with which to encrypt the message." ) ;
return null ;
}
var prand = "" ;
for ( var i = 0 ; i < keyt . length ; i ++ ) {
prand += keyt . charCodeAt ( i ) . toString ( ) ;
}
var sPos = Math . floor ( prand . length / 5 ) ;
var mult = parseInt ( prand . charAt ( sPos ) + prand . charAt ( sPos * 2 ) + prand . charAt ( sPos * 3 ) + prand . charAt ( sPos * 4 ) + prand . charAt ( sPos * 5 ) ) ;
var incr = Math . ceil ( keyt . length / 2 ) ;
var modu = Math . pow ( 2 , 31 ) - 1 ;
if ( mult < 2 ) {
alert ( "Algorithm cannot find a suitable hash. Please choose a different password. \nPossible considerations are to choose a more complex or longer password." ) ;
return null ;
}
// var salt = Math.round(Math.random() * 1000000000) % 100000000;
var salt = 101 ;
prand += salt ;
while ( prand . length > 10 ) {
prand = ( parseInt ( prand . substring ( 0 , 10 ) ) + parseInt ( prand . substring ( 10 , prand . length ) , 10 ) ) . toString ( ) ;
}
prand = ( mult * prand + incr ) % modu ;
var enc _chr = "" ;
var enc _str = "" ;
for ( var i = 0 ; i < str . length ; i ++ ) {
enc _chr = parseInt ( str . charCodeAt ( i ) ^ Math . floor ( ( prand / modu ) * 255 ) ) ;
if ( enc _chr < 16 ) {
enc _str += "0" + enc _chr . toString ( 16 ) ;
} else {
enc _str += enc _chr . toString ( 16 ) ;
}
prand = ( mult * prand + incr ) % modu ;
}
salt = salt . toString ( 16 ) ;
while ( salt . length < 8 ) {
salt = "0" + salt ;
}
enc _str += salt ;
return enc _str ;
} ,
/ * *
* 对加密后的字符串解密 { @ link # encrypt }
* @ static
* @ param str 加密过的字符 <EFBFBD> ?
* @ param keyt 密钥
* @ returns { String } 解密后的字符 <EFBFBD> ?
* 通用加密方法
* /
decrypt : function ( str , keyt ) {
if ( str == "" ) {
return "" ;
encrypt : function ( type , text , key ) {
switch ( type ) {
case BI . CRYPT _TYPE . AES :
default :
return BI . aesEncrypt ( text , key ) ;
}
if ( ! keyt || keyt == "" ) {
keyt = "655" ;
}
keyt = escape ( keyt ) ;
if ( str == null || str . length < 8 ) {
return ;
}
if ( keyt == null || keyt . length <= 0 ) {
return ;
}
var prand = "" ;
for ( var i = 0 ; i < keyt . length ; i ++ ) {
prand += keyt . charCodeAt ( i ) . toString ( ) ;
}
var sPos = Math . floor ( prand . length / 5 ) ;
var tempmult = prand . charAt ( sPos ) + prand . charAt ( sPos * 2 ) + prand . charAt ( sPos * 3 ) + prand . charAt ( sPos * 4 ) ;
if ( sPos * 5 < prand . length ) {
tempmult += prand . charAt ( sPos * 5 ) ;
}
var mult = parseInt ( tempmult ) ;
var incr = Math . round ( keyt . length / 2 ) ;
var modu = Math . pow ( 2 , 31 ) - 1 ;
var salt = parseInt ( str . substring ( str . length - 8 , str . length ) , 16 ) ;
str = str . substring ( 0 , str . length - 8 ) ;
prand += salt ;
while ( prand . length > 10 ) {
prand = ( parseInt ( prand . substring ( 0 , 10 ) , 10 ) + parseInt ( prand . substring ( 10 , prand . length ) , 10 ) ) . toString ( ) ;
}
prand = ( mult * prand + incr ) % modu ;
var enc _chr = "" ;
var enc _str = "" ;
for ( var i = 0 ; i < str . length ; i += 2 ) {
enc _chr = parseInt ( parseInt ( str . substring ( i , i + 2 ) , 16 ) ^ Math . floor ( ( prand / modu ) * 255 ) ) ;
enc _str += String . fromCharCode ( enc _chr ) ;
prand = ( mult * prand + incr ) % modu ;
}
return unescape ( enc _str ) ;
} ,
/ * *