var sipboxId1='SIPBox1'; var sipboxId2='SIPBox2'; var sipboxId3='SIPBox3'; var sipboxId4='SIPBox4'; var sipboxId5='SIPBox5'; var sip1,sip2,sip3,sip4,sip5; var sip1OpenKeyBord = false; var sip2OpenKeyBord = false; var sip3OpenKeyBord = false; var sip4OpenKeyBord = false; var sip5OpenKeyBord = false; var CFCAPasswordDefaults = { base64ServerRandom:'MTIzNDU2Nzg5MDk4NzY1NA==', minLength:6, maxLength:16, randomType: RANDOM_DIGITAL_LETTER, //虚拟键盘乱序类型 cipherType:CIPHER_TYPE_SM2, outputType:OUTPUT_TYPE_ORIGINAL, inputRegex:'^\S$' }; //点击小键盘外事件时,关闭小键盘 $(document).on('click',function(e){ if(!(($(e.target).is("#toggle1") || $(e.srcElement).is("#toggle1")) || ($(e.target).is("#toggle2") || $(e.srcElement).is("#toggle2")) || ($(e.target).is("#toggle3") || $(e.srcElement).is("#toggle3")) || ($(e.target).is("#toggle4") || $(e.srcElement).is("#toggle4")) || ($(e.target).is("#toggle5") || $(e.srcElement).is("#toggle5")) )){ if(!(($(e.target).is("#cfcaSafeCanvas") || $(e.srcElement).is("#cfcaTopBar")) || ($(e.target).is("#cfcaSafeCanvas") || $(e.srcElement).is("#cfcaTopBar")) )){ if(sip1!=undefined && sip1OpenKeyBord){ sip1.hideKeyboard(sip1); sip1OpenKeyBord = false; } if(sip2!=undefined && sip2OpenKeyBord){ sip2.hideKeyboard(sip2); sip2OpenKeyBord = false; } if(sip3!=undefined && sip3OpenKeyBord){ sip3.hideKeyboard(sip3); sip3OpenKeyBord = false; } if(sip4!=undefined && sip4OpenKeyBord){ sip4.hideKeyboard(sip4); sip4OpenKeyBord = false; } if(sip5!=undefined && sip5OpenKeyBord){ sip5.hideKeyboard(sip5); sip5OpenKeyBord = false; } } } }); function doneCallback() { hideCursor(); // alert('Done Input'); } function inputChangeCallback(sipBoxId, type, length) { var operator = type === CFCA_KEYBOARD_INSERT ? 'INSERT' : (type === CFCA_KEYBOARD_DELETE ? 'DELETE' : 'CLEAR'); // alert('sipBoxId:' + sipBoxId + ';' + 'opt:' + operator + ';' + 'len:' + length); } function initInput1() { document.msCapsLockWarningOff = true; var serverRandom = CFCAPasswordDefaults.base64ServerRandom; sip1 = new CFCASIPInput(sipboxId1, SIP_TYPE_SYSTEM_PRIORITY_HYBRID_KEYBOARD); sip1.setServerRandom(sipboxId1, serverRandom); sip1.setDoneCallback(sipboxId1, doneCallback); sip1.setInputChangeCallback(sipboxId1, inputChangeCallback); sip1.setMinLength(sipboxId1, CFCAPasswordDefaults.minLength); sip1.setMaxLength(sipboxId1, CFCAPasswordDefaults.maxLength); sip1.setCipherType(sipboxId1, CFCAPasswordDefaults.cipherType); sip1.setOutputType(sipboxId1, CFCAPasswordDefaults.outputType); // sip1.setInputRegex(sipboxId1, CFCAPasswordDefaults.inputRegex); sip1.setRandomType(sipboxId1, CFCAPasswordDefaults.randomType); sip1.enableCursor('SIPBox1Cursor'); } function initInput2() { document.msCapsLockWarningOff = true; var serverRandom = CFCAPasswordDefaults.base64ServerRandom; sip2 = new CFCASIPInput(sipboxId2, SIP_TYPE_SYSTEM_PRIORITY_HYBRID_KEYBOARD); sip2.setServerRandom(sipboxId2, serverRandom); sip2.setDoneCallback(sipboxId2, doneCallback); sip2.setInputChangeCallback(sipboxId2, inputChangeCallback); sip2.setMinLength(sipboxId2, CFCAPasswordDefaults.minLength); sip2.setMaxLength(sipboxId2, CFCAPasswordDefaults.maxLength); sip2.setCipherType(sipboxId2, CFCAPasswordDefaults.cipherType); sip2.setOutputType(sipboxId2, CFCAPasswordDefaults.outputType); // sip2.setInputRegex(sipboxId2, CFCAPasswordDefaults.inputRegex); sip2.setRandomType(sipboxId2, CFCAPasswordDefaults.randomType); sip2.enableCursor('SIPBox2Cursor'); } function initInput3() { document.msCapsLockWarningOff = true; var serverRandom = CFCAPasswordDefaults.base64ServerRandom; sip3 = new CFCASIPInput(sipboxId3, SIP_TYPE_SYSTEM_PRIORITY_HYBRID_KEYBOARD); sip3.setServerRandom(sipboxId3, serverRandom); sip3.setDoneCallback(sipboxId3, doneCallback); sip3.setInputChangeCallback(sipboxId3, inputChangeCallback); sip3.setMinLength(sipboxId3, CFCAPasswordDefaults.minLength); sip3.setMaxLength(sipboxId3, CFCAPasswordDefaults.maxLength); sip3.setCipherType(sipboxId3, CFCAPasswordDefaults.cipherType); sip3.setOutputType(sipboxId3, CFCAPasswordDefaults.outputType); // sip3.setInputRegex(sipboxId3, CFCAPasswordDefaults.inputRegex); sip3.setRandomType(sipboxId3, CFCAPasswordDefaults.randomType); sip3.enableCursor('SIPBox3Cursor'); } function initInput4() { document.msCapsLockWarningOff = true; var serverRandom = CFCAPasswordDefaults.base64ServerRandom; sip4 = new CFCASIPInput(sipboxId4, SIP_TYPE_SYSTEM_PRIORITY_HYBRID_KEYBOARD); sip4.setServerRandom(sipboxId4, serverRandom); sip4.setDoneCallback(sipboxId4, doneCallback); sip4.setInputChangeCallback(sipboxId4, inputChangeCallback); sip4.setMinLength(sipboxId4, CFCAPasswordDefaults.minLength); sip4.setMaxLength(sipboxId4, CFCAPasswordDefaults.maxLength); sip4.setCipherType(sipboxId4, CFCAPasswordDefaults.cipherType); sip4.setOutputType(sipboxId4, CFCAPasswordDefaults.outputType); // sip4.setInputRegex(sipboxId4, CFCAPasswordDefaults.inputRegex); sip4.setRandomType(sipboxId4, CFCAPasswordDefaults.randomType); sip4.enableCursor('SIPBox4Cursor'); } function initInput5() { document.msCapsLockWarningOff = true; var serverRandom = CFCAPasswordDefaults.base64ServerRandom; sip5 = new CFCASIPInput(sipboxId5, SIP_TYPE_SYSTEM_PRIORITY_HYBRID_KEYBOARD); sip5.setServerRandom(sipboxId5, serverRandom); sip5.setDoneCallback(sipboxId5, doneCallback); sip5.setInputChangeCallback(sipboxId5, inputChangeCallback); sip5.setMinLength(sipboxId5, CFCAPasswordDefaults.minLength); sip5.setMaxLength(sipboxId5, CFCAPasswordDefaults.maxLength); sip5.setCipherType(sipboxId5, CFCAPasswordDefaults.cipherType); sip5.setOutputType(sipboxId5, CFCAPasswordDefaults.outputType); // sip5.setInputRegex(sipboxId5, CFCAPasswordDefaults.inputRegex); sip5.setRandomType(sipboxId5, CFCAPasswordDefaults.randomType); sip5.enableCursor('SIPBox5Cursor'); } function getEncrypt(sipboxId) { var sip = getSIPInput(sipboxId); var sipcheck = document.getElementById(sipboxId); var len = sipcheck.innerHTML.length; if(len == 0){ alert("密码不能为空"); return 0; } if(len > 0 && len < 6){ alert("至少输入6位数密码"); return 1; } var encryptedInputValue = sip.getEncryptedInputValue(sipboxId); var passwordStrengthLevel = sip.getCipherAttributes(sipboxId); var errorCode = sip.getErrorCode(sipboxId).toString(16); if (errorCode != CFCA_OK) { alert('加密输入数据错误: 0x' + errorCode ); return; } var encryptedClientRandom = sip.getEncryptedClientRandom(sipboxId); errorCode = sip.getErrorCode(sipboxId).toString(16); if (errorCode != CFCA_OK) { alert('加密客户端随机数错误: 0x' + errorCode); } // alert('小写字母:' + passwordStrengthLevel[0]); // alert('大写字母:' + passwordStrengthLevel[1]); // alert('数字:' + passwordStrengthLevel[2]); // alert('是否完全连续:' + passwordStrengthLevel[4]); // alert('是否完全重复:' + passwordStrengthLevel[5]); // if((passwordStrengthLevel[0]==true || // passwordStrengthLevel[1]==true) && // passwordStrengthLevel[2]==true && // passwordStrengthLevel[4]==false && // passwordStrengthLevel[5]==false){ // return encryptedInputValue+','+encryptedClientRandom; // }else{ // alert("输入密码格式错误") // return false; // } //小写字母 var lowercase = passwordStrengthLevel[0]; //大写字母 var upperrcase = passwordStrengthLevel[1]; //数字 var digist = passwordStrengthLevel[2]; //符号 var symbol = passwordStrengthLevel[3]; //是否完全连续 var continus = passwordStrengthLevel[4]; //是否完全重复 var reptition = passwordStrengthLevel[5]; //最大连续数 var maxTimes = passwordStrengthLevel[6]; //最大重复数 var maxRepTimes = passwordStrengthLevel[7]; //强,中密码才能通过 if((lowercase == true && digist == true && symbol == true) || (upperrcase == true && digist == true && symbol == true) || (lowercase == true && digist == true) || (upperrcase == true && digist == true) || (symbol == true && digist == true) || (lowercase == true && symbol == true) || (upperrcase == true && symbol == true)){ return encryptedInputValue+','+encryptedClientRandom; }else{ alert("您输入密码格式错误!") return 2; } } //交易密码不是网银设置,不用校验录入规则 function getTrsEncrypt(sipboxId) { var sip = getSIPInput(sipboxId); var sipcheck = document.getElementById(sipboxId); var len = sipcheck.innerHTML.length; if(len == 0){ alert("密码不能为空"); return 0; } if(len > 0 && len < 6){ alert("至少输入6位数密码"); return 1; } var encryptedInputValue = sip.getEncryptedInputValue(sipboxId); var passwordStrengthLevel = sip.getCipherAttributes(sipboxId); var errorCode = sip.getErrorCode(sipboxId).toString(16); if (errorCode != CFCA_OK) { alert('加密输入数据错误: 0x' + errorCode ); return; } var encryptedClientRandom = sip.getEncryptedClientRandom(sipboxId); errorCode = sip.getErrorCode(sipboxId).toString(16); if (errorCode != CFCA_OK) { alert('加密客户端随机数错误: 0x' + errorCode); } // alert('小写字母:' + passwordStrengthLevel[0]); // alert('大写字母:' + passwordStrengthLevel[1]); // alert('数字:' + passwordStrengthLevel[2]); // alert('是否完全连续:' + passwordStrengthLevel[4]); // alert('是否完全重复:' + passwordStrengthLevel[5]); if(passwordStrengthLevel[2]==true && passwordStrengthLevel[0]==false && passwordStrengthLevel[1]==false && passwordStrengthLevel[3]==false){ return encryptedInputValue+','+encryptedClientRandom; }else{ alert("交易密码必须为纯数字!"); return 2; } } //登录密码重置后为纯数字 function getLgEncrypt(sipboxId) { var sip = getSIPInput(sipboxId); var sipcheck = document.getElementById(sipboxId); var len = sipcheck.innerHTML.length; if(len == 0){ alert("密码不能为空"); return 0; } if(len > 0 && len < 6){ alert("至少输入6位数密码"); return 1; } var encryptedInputValue = sip.getEncryptedInputValue(sipboxId); var passwordStrengthLevel = sip.getCipherAttributes(sipboxId); var errorCode = sip.getErrorCode(sipboxId).toString(16); if (errorCode != CFCA_OK) { alert('加密输入数据错误: 0x' + errorCode ); return; } var encryptedClientRandom = sip.getEncryptedClientRandom(sipboxId); errorCode = sip.getErrorCode(sipboxId).toString(16); if (errorCode != CFCA_OK) { alert('加密客户端随机数错误: 0x' + errorCode); } // alert('小写字母:' + passwordStrengthLevel[0]); // alert('大写字母:' + passwordStrengthLevel[1]); // alert('数字:' + passwordStrengthLevel[2]); // alert('是否完全连续:' + passwordStrengthLevel[4]); // alert('是否完全重复:' + passwordStrengthLevel[5]); //不进行校验,注册时可能为弱,中,强密码 // if( passwordStrengthLevel[2]==true && // passwordStrengthLevel[4]==false && // passwordStrengthLevel[5]==false){ // return encryptedInputValue+','+encryptedClientRandom; // }else{ // alert("输入密码格式错误") // return false; // } return encryptedInputValue+','+encryptedClientRandom; } function checkEqual(sipboxId1, sipboxId2) { var sipInput1 = getSIPInput(sipboxId1); var sip1 = document.getElementById(sipboxId1); var sip2 = document.getElementById(sipboxId2); if (sip1.innerHTML.length == 0 || sip2.innerHTML.length == 0) { alert("输入数据为空"); return; } if (sipInput1.checkInputValueMatch(sipboxId1, sipboxId2)) { alert('SIPBox1与SIPBox2输入内容一致!'); } else { alert('SIPBox1与SIPBox2输入内容不一致!'); } } function showSoftKeyboard(inputid) { if(inputid == 'SIPBox1'){ sip1.showKeyboard(inputid); if(sip2)sip2.hideKeyboard(); if(sip3)sip3.hideKeyboard(); if(sip4)sip4.hideKeyboard(); if(sip5)sip5.hideKeyboard(); sip1OpenKeyBord = true; }else if (inputid == 'SIPBox2') { if(sip1)sip1.hideKeyboard(); sip2.showKeyboard(inputid); if(sip3)sip3.hideKeyboard(); if(sip4)sip4.hideKeyboard(); if(sip5)sip5.hideKeyboard(); sip2OpenKeyBord = true; } else if (inputid == 'SIPBox3') { if(sip1)sip1.hideKeyboard(); if(sip2)sip2.hideKeyboard(); sip3.showKeyboard(inputid); if(sip4)sip4.hideKeyboard(); if(sip5)sip5.hideKeyboard(); sip3OpenKeyBord = true; } else if (inputid == 'SIPBox4') { if(sip1)sip1.hideKeyboard(); if(sip2)sip2.hideKeyboard(); if(sip3)sip3.hideKeyboard(); sip4.showKeyboard(inputid); if(sip5)sip5.hideKeyboard(); sip4OpenKeyBord = true; }else if(inputid == 'SIPBox5'){ if(sip1)sip1.hideKeyboard(); if(sip2)sip2.hideKeyboard(); if(sip3)sip3.hideKeyboard(); if(sip4)sip4.hideKeyboard(); sip5.bindSIPInputBox(inputid); sip5.showKeyboard(inputid); sip5OpenKeyBord = true; } //改变键盘z-index document.getElementById("cfcaSafeCanvas").style.zIndex = "9999"; //改变topbar的z-index document.getElementById("cfcaTopBar").style.zIndex = "9999"; } function showCursor(inputid) { if (inputid == 'SIPBox1') { sip1.showCursor(); if(sip2)sip2.hideCursor(); if(sip3)sip3.hideCursor(); if(sip4)sip4.hideCursor(); if(sip5)sip5.hideCursor(); } else if (inputid == 'SIPBox2') { if(sip1)sip1.hideCursor() sip2.showCursor(); if(sip3)sip3.hideCursor(); if(sip4)sip4.hideCursor(); if(sip5)sip5.hideCursor(); } else if (inputid == 'SIPBox3') { if(sip1)sip1.hideCursor(); if(sip2)sip2.hideCursor(); sip3.showCursor(); if(sip4)sip4.hideCursor(); if(sip5)sip5.hideCursor(); } else if (inputid == 'SIPBox4') { if(sip1)sip1.hideCursor(); if(sip2)sip2.hideCursor(); if(sip3)sip3.hideCursor(); sip4.showCursor(); if(sip5)sip5.hideCursor(); }else if (inputid == 'SIPBox5') { if(sip1)sip1.hideCursor(); if(sip2)sip2.hideCursor(); if(sip3)sip3.hideCursor(); if(sip4)sip4.hideCursor(); sip5.showCursor(); } } function hideCursor() { if(sip1){ sip1.hideCursor(); //判断是否进行密码校验的判断 if(document.getElementById('SIPBox1Pass')){ checkLoginPassword('SIPBox1'); } } if(sip2){ sip2.hideCursor(); //判断是否进行密码校验的判断 if(document.getElementById('SIPBox2Pass')){ checkLoginPassword('SIPBox2'); } } if(sip3){ sip3.hideCursor(); } if(sip4){ sip4.hideCursor(); } if(sip5){ sip5.hideCursor(); } } function clearLog() { var p = document.getElementById('log'); p.innerHTML = ''; } function getSIPInput(sipboxId) { if (sipboxId == 'SIPBox1') { return sip1; } else if (sipboxId == 'SIPBox2') { return sip2; } else if (sipboxId == 'SIPBox3') { return sip3; } else if(sipboxId == 'SIPBox4'){ return sip4; }else if(sipboxId == 'SIPBox5'){ return sip5; } } function setProperty(sipboxId) { var sipInput = getSIPInput(sipboxId); var outputType = document.getElementById('outputTypeHash').checked ? OUTPUT_TYPE_HASH : OUTPUT_TYPE_ORIGINAL; var cipherType = document.getElementById('cipherTypeSM2').checked ? CIPHER_TYPE_SM2 : CIPHER_TYPE_RSA; var minLength = parseInt(document.getElementById('minLength').value); var maxLength = parseInt(document.getElementById('maxLength').value); var inputRegex = document.getElementById('inputRegex').value; var serverRandom = document.getElementById('serverRandom').value; var keywords = document.getElementById('keywords').value; var randomType = document.getElementById('NONE').checked ? RANDOM_NONE : (document.getElementById('DIGITAL').checked ? RANDOM_DIGITAL : (document.getElementById('LETTER').checked ? RANDOM_LETTER : RANDOM_DIGITAL_LETTER)); if (sipboxId === 'SIPBox2' || sipboxId === 'SIPBox3' || sipboxId === 'SIPBox4') { if (CFCA_OK != sipInput.setRandomType(sipboxId, randomType)) alert('setRandomType error'); } if (CFCA_OK != sipInput.setMinLength(sipboxId, minLength)) alert('setMinLength error'); if (CFCA_OK != sipInput.setMaxLength(sipboxId, maxLength)) alert('setMaxLength error'); if (CFCA_OK != sipInput.setOutputType(sipboxId, outputType)) alert('setOutputType error'); if (CFCA_OK != sipInput.setServerRandom(sipboxId, serverRandom)) alert('setServerRandom error'); if (CFCA_OK != sipInput.setCipherType(sipboxId, cipherType)) alert('setCipherType error'); if (CFCA_OK != sipInput.setInputRegex(sipboxId, inputRegex)) alert('setInputRegex error'); if (CFCA_OK != sipInput.setLogoImage(ImageData)) alert('setLogoImage error'); //设置logo图片 if (CFCA_OK != sipInput.setKeywords(sipboxId, keywords)) alert('setKeywords error'); //设置关键字 } function clearInput(sipboxId) { var sip = getSIPInput(sipboxId); sip.clearInputValue(sipboxId); } //function getEncrypt(sipboxId) { //var sip = getSIPInput(sipboxId); //var resultTextarea = document.getElementById('encryptedResult'); //resultTextarea.value = ''; //var encryptedInputValue = sip.getEncryptedInputValue(sipboxId); //var passwordStrengthLevel = sip.getCipherAttributes(sipboxId); //var errorCode = sip.getErrorCode(sipboxId).toString(16); //if (errorCode != CFCA_OK) { // resultTextarea.value += '加密输入数据错误: 0x' + errorCode + '\n'; // return; //} else { // resultTextarea.value += '加密输入数据: ' + encryptedInputValue + '\n'; //} //var encryptedClientRandom = sip.getEncryptedClientRandom(sipboxId); //errorCode = sip.getErrorCode(sipboxId).toString(16); //if (errorCode != CFCA_OK) { // resultTextarea.value += '加密客户端随机数错误: 0x' + errorCode + '\n'; //} else { // resultTextarea.value += '加密客户端随机数: ' + encryptedClientRandom + '\n'; //} //resultTextarea.value += '弱密码判断:'; //resultTextarea.value += '小写字母:' + passwordStrengthLevel[0]; //resultTextarea.value += '大写字母:' + passwordStrengthLevel[1]; //resultTextarea.value += '数字:' + passwordStrengthLevel[2]; //resultTextarea.value += '符号:' + passwordStrengthLevel[3]; //resultTextarea.value += '是否完全连续:' + passwordStrengthLevel[4]; //resultTextarea.value += '是否完全重复:' + passwordStrengthLevel[5]; //resultTextarea.value += '连续字符个数:' + passwordStrengthLevel[6]; //resultTextarea.value += '重复字符个数:' + passwordStrengthLevel[7]; //} /** * 判断密码的强度 */ function checkLoginPassword(inputid){ var sip = document.getElementById(inputid); var len = sip.innerHTML.length; if(len == 0){ document.getElementById(inputid + 'Pass').style.color='red'; document.getElementById(inputid + 'Pass').innerHTML = '请输入密码'; return false; } if(len > 0 && len < 6){ document.getElementById(inputid + 'Pass').style.color='red'; document.getElementById(inputid + 'Pass').innerHTML = '至少输入6位数密码'; return false; } var msg = checkPassWordStronger(inputid,len); if(msg == '中'){ document.getElementById(inputid + 'Pass').style.color='blue'; }else if(msg == '强'){ document.getElementById(inputid + 'Pass').style.color='green'; }else{ document.getElementById(inputid + 'Pass').style.color='red'; } document.getElementById(inputid + 'Pass').innerHTML = msg; } /** * 用于判断密码的强度 * 判断规则: * 1、长度不足6位:抛错:密码长度为6-16位 * 2、弱密码:纯数字;纯小写字母;纯大写字母;纯大小写字母;(纯特殊字符;数字+密码(2/3以上内容一样);数字+特殊字符(2/3以上内容一样)) * 3、中密码:数字+字母;数字+特殊字符;字母+特殊字符 * 4、强密码:数字+字母+特殊字符 */ function checkPassWordStronger(sipboxId,len) { var sip = getSIPInput(sipboxId); var passwordStrengthLevel = sip.getCipherAttributes(sipboxId); //小写字母 var lowercase = passwordStrengthLevel[0]; //大写字母 var upperrcase = passwordStrengthLevel[1]; //数字 var digist = passwordStrengthLevel[2]; //符号 var symbol = passwordStrengthLevel[3]; //是否完全连续 var continus = passwordStrengthLevel[4]; //是否完全重复 var reptition = passwordStrengthLevel[5]; //最大连续数 var maxTimes = passwordStrengthLevel[6]; //最大重复数 var maxRepTimes = passwordStrengthLevel[7]; //强密码:数字+字母+特殊字符 if((lowercase == true && digist == true && symbol == true) || (upperrcase == true && digist == true && symbol == true)){ return '强'; //中密码:数字+字母;数字+特殊字符;字母+特殊字符 }else if(((lowercase == true && digist == true) || (upperrcase == true && digist == true) || (symbol == true && digist == true) || (lowercase == true && symbol == true) || (upperrcase == true && symbol == true)) && maxRepTimes/len < 2/3){ return '中'; //弱密码:纯数字;纯小写字母;纯大写字母;纯大小写字母;(纯特殊字符;数字+密码(2/3以上内容一样);数字+特殊字符(2/3以上内容一样)) }else if(lowercase == true || upperrcase ==true || digist == true || symbol == true || continus == true || reptition == true || maxRepTimes/len > 2/3){ return '弱'; } }