Index: ssts-web/src/main/webapp/js/base64/base64Encrypt.js =================================================================== diff -u -r35076 -r35091 --- ssts-web/src/main/webapp/js/base64/base64Encrypt.js (.../base64Encrypt.js) (revision 35076) +++ ssts-web/src/main/webapp/js/base64/base64Encrypt.js (.../base64Encrypt.js) (revision 35091) @@ -146,20 +146,44 @@ } //r加密(参数为明文) -function encryptText(text){ - return base64encode(utf16to8(text)); +function encryptText(text,depth){ + var result = ""; + try{ + var depthIt = parseInt(depth,10); + result = base64encode(utf16to8(text)); + if(depthIt > 1){ + for(var i = 1;i < depthIt;i++){ + result = base64encode(utf16to8(result)); + } + } + }catch(e){ + result = base64encode(utf16to8(text)); + } + return result; } //解密(参数为密文) -function dencryptText(text){ - return utf8to16(base64decode(text)); +function dencryptText(text,depth){ + var result = ""; + try{ + var depthIt = parseInt(depth,10); + result = utf8to16(base64decode(text)); + if(depthIt > 1){ + for(var i = 1;i < depthIt;i++){ + result = base64decode(utf16to8(result)); + } + } + }catch(e){ + result = utf8to16(base64decode(text)); + } + return result; } //示例函数 function doit() {   var f = document.f   /*f.output.value = base64encode(utf16to8(f.source.value))   f.decode.value = utf8to16(base64decode(f.output.value))*/ - f.output.value = encryptText(f.source.value); - f.decode.value = dencryptText(f.output.value); + f.output.value = encryptText(f.source.value,f.depth.value); + f.decode.value = dencryptText(f.output.value,f.depth.value); } \ No newline at end of file Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/basedatamanager/deviceinterface/DeviceInterface.java =================================================================== diff -u -r35076 -r35091 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/basedatamanager/deviceinterface/DeviceInterface.java (.../DeviceInterface.java) (revision 35076) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/basedatamanager/deviceinterface/DeviceInterface.java (.../DeviceInterface.java) (revision 35091) @@ -308,7 +308,7 @@ @Transient public String getDecryptUserName() { try { - return CoderEncryption.decryptBASE64(userName); + return CoderEncryption.decryptBASE64(userName,CoderEncryption.DEVICEINTERFACE_ENCRPT_DEPTH); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -333,7 +333,7 @@ @Transient public String getDecryptPassword() { try { - return CoderEncryption.decryptBASE64(password); + return CoderEncryption.decryptBASE64(password,CoderEncryption.DEVICEINTERFACE_ENCRPT_DEPTH); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Index: forgon-tools/src/main/java/com/forgon/tools/crypto/coder/CoderEncryption.java =================================================================== diff -u -r35076 -r35091 --- forgon-tools/src/main/java/com/forgon/tools/crypto/coder/CoderEncryption.java (.../CoderEncryption.java) (revision 35076) +++ forgon-tools/src/main/java/com/forgon/tools/crypto/coder/CoderEncryption.java (.../CoderEncryption.java) (revision 35091) @@ -46,6 +46,11 @@ public static final String KEY_MAC = "HmacMD5"; /** + * 设备接口用户名和密码加密深度,默认为3.详见:GDSRMYY-544 + */ + public static final int DEVICEINTERFACE_ENCRPT_DEPTH = 3; + + /** * BASE64解密,返回byte数组 * * @param key 要解密的字符串(密文) @@ -68,6 +73,24 @@ } /** + * BASE64解密,返回明文字符串 + * + * @param key 要解密的字符串(密文) + * @param depth + * @return String + * @throws Exception + */ + public static String decryptBASE64(String key,int depth) throws Exception { + String result = new String(decryptBASE64ReturnByteArray(key)); + if(depth > 1){ + for (int i = 1; i < depth; i++) { + result = new String(decryptBASE64ReturnByteArray(result)); + } + } + return result; + } + + /** * BASE64加密 * * @param key @@ -79,6 +102,23 @@ } /** + * BASE64加密 + * + * @param key + * @return + * @throws Exception + */ + public static String encryptBASE64(byte[] key,int depth) throws Exception { + String result = new String(encryptBASE64(key)); + if(depth > 1){ + for (int i = 1; i < depth; i++) { + result = new String(encryptBASE64(result.getBytes())); + } + } + return result; + } + + /** * MD5加密 * * @param data @@ -107,7 +147,7 @@ } /** - * 将密码邮明文生成对应的md5密码。用户的密码加密码建议调用此方法 + * 将密码由明文生成对应的md5密码。用户的密码加密码建议调用此方法 * @param password * @return */ @@ -164,13 +204,20 @@ } public static void main(String[] args) throws Exception { - String password = "123456"; + String password = "1"; /*System.out.println("md5-1=" + new String(encryptMD5(password,com.forgon.tools.Constants.CHARSET_UTF8))); System.out.println("md5-2=" + encryptMD5ForSpringSecurity(password));*/ - String encrypt = encryptBASE64(password.getBytes()); + String encrypt = encryptBASE64(password.getBytes(),DEVICEINTERFACE_ENCRPT_DEPTH); System.out.println("encrypt=" + encrypt); - System.out.println("dencrypt=" + decryptBASE64(encrypt)); + System.out.println("dencrypt=" + decryptBASE64(encrypt,DEVICEINTERFACE_ENCRPT_DEPTH)); + + //js的base64编码3次后的密文 + String encrypted1 = "VFZFOVBRPT0="; + //本java类的base64编码3次后的密文 + String encrypted2 = "VFZFOVBRMEsNCg=="; + System.out.println("dencrypt1=" + decryptBASE64(encrypted1,DEVICEINTERFACE_ENCRPT_DEPTH)); + System.out.println("dencrypt2=" + decryptBASE64(encrypted2,DEVICEINTERFACE_ENCRPT_DEPTH)); } } Index: ssts-maintain/src/main/java/com/forgon/disinfectsystem/maintain/basic/service/MaintainManagerImpl.java =================================================================== diff -u -r35076 -r35091 --- ssts-maintain/src/main/java/com/forgon/disinfectsystem/maintain/basic/service/MaintainManagerImpl.java (.../MaintainManagerImpl.java) (revision 35076) +++ ssts-maintain/src/main/java/com/forgon/disinfectsystem/maintain/basic/service/MaintainManagerImpl.java (.../MaintainManagerImpl.java) (revision 35091) @@ -1773,10 +1773,10 @@ String realUserName = deviceInterface.getRealUserName(); String realPassword = deviceInterface.getRealPassword(); if(StringUtils.isNotBlank(realUserName)){ - deviceInterface.setUserName(CoderEncryption.encryptBASE64(realUserName.getBytes())); + deviceInterface.setUserName(CoderEncryption.encryptBASE64(realUserName.getBytes(),CoderEncryption.DEVICEINTERFACE_ENCRPT_DEPTH)); } if(StringUtils.isNotBlank(realPassword)){ - deviceInterface.setPassword(CoderEncryption.encryptBASE64(realPassword.getBytes())); + deviceInterface.setPassword(CoderEncryption.encryptBASE64(realPassword.getBytes(),CoderEncryption.DEVICEINTERFACE_ENCRPT_DEPTH)); } } catch (Exception e) { // TODO Auto-generated catch block Index: ssts-web/src/main/webapp/js/base64/base64EncryptSample.jsp =================================================================== diff -u -r35076 -r35091 --- ssts-web/src/main/webapp/js/base64/base64EncryptSample.jsp (.../base64EncryptSample.jsp) (revision 35076) +++ ssts-web/src/main/webapp/js/base64/base64EncryptSample.jsp (.../base64EncryptSample.jsp) (revision 35091) @@ -15,6 +15,6 @@

Base64 decode


- +加密深度: \ No newline at end of file