fullstack.web/swa/u/test2.html
2022-12-22 14:57:51 +08:00

1598 lines
62 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="./jquery.min.js"></script>
<script type="text/javascript" src="./fiseckey.js"></script>
<Script language="JavaScript">
var hDevice = 0;
//打印信息
function PrintInfo(info) {
form1.mytext.value = form1.mytext.value + info + "\r\n";
document.getElementById("mytext").scrollTop = document.getElementById("mytext").scrollHeight;
}
function PrintInfo1(info) {
document.form1.mytext.value = document.form1.mytext.value + "\n\r" + info;
document.form1.mytext.doScroll;
}
function test(){
FISECKEY.signData("3333333", 1, "callSignData", callSignData);
}
function opendevice(){
var DevID = form1.devid.value;
try {
hDevice = FISECKEY.OpenDevice(DevID,keyType);
PrintInfo(hDevice);
}
catch (e) {
PrintInfo(e.message);
}
}
function closedevice(){
try {
FISECKEY.CloseDevice(hDevice);
hDevice = 0;
PrintInfo("关闭成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//通过序列号打开设备
function OpenDevBySerial() {
var DevSerial = form1.txtDeviceSerial.value;
var vs = form1.devtype;
var Type;
for (var i = 0; i < vs.length; i++) {
if (vs[i].checked) {
Type = vs[i].value;
break;
}
}
try {
hDevice = FISECKEY.OpenBySerial(DevSerial, Type);
PrintInfo(hDevice);
}
catch (e) {
PrintInfo(e.message);
}
}
//通过设备名称打开设备
function OpenDeviceByName() {
var DevID = form1.txtDeviceID2.value;
var DevName = form1.txtDeviceName.value;
var vs = form1.devtype;
var Type;
for (var i = 0; i < vs.length; i++) {
if (vs[i].checked) {
Type = vs[i].value;
break;
}
}
try {
hDevice = FISECKEY.OpenByName(DevName, 0, 0);
PrintInfo(hDevice);
}
catch (e) {
PrintInfo(e.message);
}
}
//枚举序列号与名称
function EnumDevByArray() {
var List;
try {
List = FISECKEY.EnumByArray();
PrintInfo(List);
}
catch (e) {
PrintInfo(e.message);
}
}
function EnumDevByName() {
var List;
try {
List = FISECKEY.EnumByName();
PrintInfo(List);
}
catch (e) {
PrintInfo(e.message);
}
}
//枚举设备序列号
function EnumDevBySerial() {
var List;
try {
List = FISECKEY.EnumBySerial();
PrintInfo(List);
}
catch (e) {
PrintInfo(e.message);
}
}
//获取设备信息
function GetDevInfo() {
var List;
var Type = 1284;
try {
FISECKEY.getInfo(hDevice, "callGetDevInfo", callGetDevInfo);
}
catch (e) {
PrintInfo(e.message);
}
}
//设置设备名称
function SetDeviceName() {
var DevName = form1.DeviceName2.value;
try {
FISECKEY.SetDevName(hDevice, DevName);
PrintInfo("设置成功");
}
catch (e) {
PrintInfo(e.message);
}
}
function GetDeviceName(){
var DevName;
try {
DevName = FISECKEY.GetDevName(hDevice);
PrintInfo(DevName);
}
catch (e) {
PrintInfo(e.message);
}
}
//获取随机数
function GenRandom() {
var Rnd;
var Len = form1.txtRandLen.value;
try {
Rnd = FISECKEY.GenRandom(hDevice, parseInt(Len));
PrintInfo(Rnd);
}
catch (e) {
PrintInfo(e.message);
}
}
//产生指定模长的RSA非对称密钥
function GenRSAKeyPair() {
var Flag = 0;
var Index = form1.txtRsaKeyId.value;
var keyLength;
var vs = form1.rdRsaModeLen;
for (var i = 0; i < vs.length; i++) {
if (vs[i].checked) {
keyLength = vs[i].value;
break;
}
}
try {
FISECKEY.GenRSAKeypair(hDevice, Flag, parseInt(keyLength), parseInt(Index));
PrintInfo("OK");
}
catch (e) {
PrintInfo(e.message);
}
}
//删除设备内部存储的RSA密钥对
function DelRSAKeyPair() {
var Index = form1.txtRsaKeyId.value;
try {
FISECKEY.DelRSAKeypair(hDevice, parseInt(Index));
PrintInfo("OK");
}
catch (e) {
PrintInfo(e.message);
}
}
//把RSA私钥从主机导入到设备内部并存储
function ImportRSAPriKeyBase64() {
var vRsakey = form1.TextareaRsaKeyBuf.value;
var Index = form1.txtImportRsaKeyId.value;
var Flag = 0;
var Bits;
var vs = form1.rdImportRsaModeLen;
for (var i = 0; i < vs.length; i++) {
if (vs[i].checked) {
Bits = vs[i].value;
break;
}
}
try {
FISECKEY.ImportRSAKey(hDevice, parseInt(Index), parseInt(Bits), Flag, vRsakey);
PrintInfo("OK");
}
catch (e) {
PrintInfo(e.message);
}
}
//使用RSA公钥对输入数据进行RSA加密运算
function RSAEncrypt() {
var vInData = form1.txtRsaInbuf.value;
var vIndex = form1.txtEnDeRsaKeyId.value;
var enData;
try {
enData = FISECKEY.RSAEncrypt(hDevice, parseInt(vIndex), vInData);
PrintInfo(enData);
}
catch (e) {
PrintInfo(e.message);
}
}
//使用RSA私钥对密文数据进行RSA解密运算
function RSADecrypt() {
var decData;
var vInData = form1.txtCipherBuf.value;
var vIndex = form1.txtEnDeRsaKeyId.value;
try {
decData = FISECKEY.RSADecrypt(hDevice, parseInt(vIndex), vInData);
PrintInfo(decData);
}
catch (e) {
PrintInfo(e.message);
}
}
//对明文数据进行签名
function RSASign() {
var sigData;
var vInData = form1.txtRsaInbuf.value;
var vIndex = form1.txtEnDeRsaKeyId.value;
//var vHashAlg = 3; //FM_ALG_SHA1
try {
sigData = FISECKEY.RSASignData(hDevice, parseInt(vIndex), vInData);
PrintInfo(sigData);
}
catch (e) {
PrintInfo(e.message);
}
}
//对明文数据及签名数据进行验证
function RSAVerify() {
var vIndex = form1.txtEnDeRsaKeyId.value;
var vInData = form1.txtRsaInbuf.value;
var vSignData = form1.txtCipherBuf.value;
var vHashAlg = 3; //FM_ALG_SHA1
try {
FISECKEY.RSAVerify(hDevice, parseInt(vIndex), vHashAlg, vInData, vSignData);
PrintInfo("验证成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//生成ECC密钥
function GenECCKeypair() {
var vAlg = 0;
var hKey = form1.txtECCKeyID.value;
var vKeyBits = 256;
try {
FISECKEY.GenECCKeypair(hDevice, vAlg, vKeyBits, parseInt(hKey));
PrintInfo("生成ECC密钥对成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//删除ECC密钥
function DelECCKeypair() {
var hKey = form1.txtECCKeyID.value;;
try {
FISECKEY.DelECCKeypair(hDevice, parseInt(hKey));
PrintInfo("删除ECC密钥对成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//导入ECC密钥对
function ImportECCKeypair2() {
var hKey = form1.txtECCKeyID1.value;
var vStrECCPubkey = form1.txtECCPubKeyData.value;
var vStrECCPrikey = form1.txtECCPriKeyData.value;
var flag = 1;
var dwKeyBits = 256;
try {
FISECKEY.ImportECCKeypair(hDevice, parseInt(hKey), dwKeyBits, flag, vStrECCPubkey, vStrECCPrikey);
PrintInfo("导入ECC密钥对成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//导出ECC公钥
function ExportECCKeypair() {
var vstrInfo;
var hKey = form1.txtECCKeyID.value;
try {
vstrInfo = FISECKEY.ExportECCKeypair(hDevice, hKey);
PrintInfo(vstrInfo);
}
catch (e) {
PrintInfo(e.message);
}
}
//使用指定ECC密钥对数据进行加密
function ECCEncrypt() {
var enData;
var vAlg = 1;
var hKey = form1.txtEccEnDeKeyID.value;
var vInbuf = form1.txtECCInBuf.value;
var txtCipherData = form1.txtECCCipherBuf;
try {
enData = FISECKEY.ECCEncrypt(hDevice, 0, parseInt(hKey), vInbuf);
PrintInfo(enData);
}
catch (e) {
PrintInfo(e.message);
}
}
//使用指定ECC密钥对数据进行解密
function ECCDecrypt() {
var decData;
var vAlg = 1;
var hKey = form1.txtEccEnDeKeyID.value;
var vCipher = form1.txtECCCipherBuf.value;
var txtOutData = form1.txtECCOutBuf;
try {
decData = FISECKEY.ECCDecrypt(hDevice, 0, parseInt(hKey), vCipher);
PrintInfo(decData);
}
catch (e) {
PrintInfo(e.message);
}
}
//使用指定ECC密钥对数据进行加密
function ECCEncryptDer() {
var enData;
var vAlg = 1;
var hKey = form1.txtEccEnDeKeyID.value;
var vInbuf = form1.txtECCInBuf.value;
var txtCipherData = form1.txtECCCipherBuf;
try {
enData = FISECKEY.ECCEncryptDer(hDevice, 0, parseInt(hKey), vInbuf);
PrintInfo(enData);
}
catch (e) {
PrintInfo(e.message);
}
}
//使用指定ECC密钥对数据进行解密
function ECCDecryptDer() {
var decData;
var vAlg = 1;
var hKey = form1.txtEccEnDeKeyID.value;
var vCipher = form1.txtECCCipherBuf.value;
var txtOutData = form1.txtECCOutBuf;
try {
decData = FISECKEY.ECCDecryptDer(hDevice, 0, parseInt(hKey), vCipher);
PrintInfo(decData);
}
catch (e) {
PrintInfo(e.message);
}
}
//使用指定ECC密钥对数据进行签名
function ECCSign() {
var sigData;
var vAlg = 1;
var hKey = form1.txtECCKeyID.value;
var vInbuf = form1.txtECCInBuf.value;
try {
sigData = FISECKEY.ECCSign(hDevice, vAlg, parseInt(hKey), vInbuf);
PrintInfo(sigData);
}
catch (e) {
PrintInfo(e.message);
}
}
//使用指定ECC密钥对签名进行验证
function ECCVerify() {
var ret;
var vAlg = 1;
var hKey = form1.txtECCKeyID.value;
var vInbuf = form1.txtECCInBuf.value;
var vSignature = form1.txtECCCipherBuf.value;
try {
FISECKEY.ECCVerify(hDevice, vAlg, parseInt(hKey), vInbuf, vSignature);
PrintInfo("验证成功!");
}
catch (e) {
PrintInfo(e.message);
}
}
//Hash运算
function Hash() {
var vHashAlg = 3;
var vCipher;
var vInData = form1.TextHash.value;
try {
vCipher = FISECKEY.Hash(hDevice, vHashAlg, vInData);
PrintInfo(vCipher);
}
catch (e) {
PrintInfo(e.message);
}
}
//使用SM3算法进行Hash运算
function SM3Data() {
var vPubKey = form1.txtSM2PubkeyID.value;
var vInbuf = form1.TextHash.value;
try {
var vstrInfo;
vstrInfo = FISECKEY.SM3Data(hDevice, parseInt(vPubKey), vInbuf);
PrintInfo(vstrInfo);
}
catch (e) {
PrintInfo(e.message);
}
}
//导入证书到指定密钥容器
function ContainerWriteCert() {
var vContainerName = form1.txtContainerName2.value;
var vCertData = form1.TextareaCertData.value;
var vFlag; //1加密证书2签名证书3加密证书密钥号4签名证书密钥号
var vs = form1.rdCertType;
for (var i = 0; i < vs.length; i++) {
if (vs[i].checked) {
vFlag = vs[i].value;
break;
}
}
try {
FISECKEY.ContainerWriteCert(hDevice, parseInt(vFlag), vContainerName, vCertData);
PrintInfo("导入证书成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//导出证书
function ContainerReadCert() {
var result;
var vContainerName = form1.txtContainerName2.value;
var vFlag; //1加密证书2签名证书3加密证书密钥号4签名证书密钥号
var vs = form1.rdCertType;
for (var i = 0; i < vs.length; i++) {
if (vs[i].checked) {
vFlag = vs[i].value;
break;
}
}
try {
result = FISECKEY.ContainerReadCert(hDevice, parseInt(vFlag), vContainerName);
PrintInfo(result);
}
catch (e) {
PrintInfo(e.message);
}
}
//导出证书
function GetSerialAndSubjects() {
var result;
try {
result = FISECKEY.getSerialAndSubjects(hDevice);
PrintInfo(result);
}
catch (e) {
PrintInfo(e.message);
}
}
//枚举密钥容器
function ContainerEnum() {
var result;
try {
result = FISECKEY.ContainerEnum(hDevice);
PrintInfo(result);
}
catch (e) {
PrintInfo(e.message);
}
}
//删除密钥容器
function DelContainer() {
var vContainerName = form1.txtContainerName.value;
try {
FISECKEY.ContainerDelete(hDevice, vContainerName);
PrintInfo("删除成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//创建文件
function FILE_CreateFile() {
var vstrDir = form1.txtDirName2.value;
var vstrfile = form1.txtFileName.value;
var vdwAccCont = form1.txtFilePerm.value;
var vdwSize = form1.txtFileSize.value;
try {
//FCOM.FILE_CreateFile(hDevice, vstrDir, vstrfile, vdwSize, vdwAccCont);
FISECKEY.FILE_CreateFile(hDevice, vstrDir, vstrfile, vdwSize, vdwAccCont);
PrintInfo("创建成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//初始化智能密码钥匙文件系统
function FILE_Init() {
try {
//FCOM.FILE_Init(hDevice);
FISECKEY.FILE_Init(hDevice);
PrintInfo("文件初始化完成");
}
catch (e) {
PrintInfo(e.message);
}
}
//根据指定的路径创建目录
function FILE_CreateDir() {
var vstrDir = form1.txtDirName.value;
var vdwAccCont = form1.txtDirPerm.value;
PrintInfo(vstrDir);
PrintInfo(vdwAccCont);
try {
//FCOM.FILE_CreateDir(hDevice, vstrDir, vdwAccCont);
FISECKEY.FILE_CreateDir(hDevice, vstrDir, parseInt(vdwAccCont));
PrintInfo("创建成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//删除指定的目录
function FILE_DeleteDir() {
var vstrDir = form1.txtDirName.value;
try {
//FCOM.FILE_DeleteDir(hDevice, vstrDir);
FISECKEY.FILE_DeleteDir(hDevice, vstrDir);
PrintInfo("删除成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//删除文件
function FILE_DeleteFile() {
var vstrfile = form1.txtFileName.value;
var vstrDir = form1.txtDirName2.value;
try {
//FCOM.FILE_DeleteFile(hDevice, vstrDir, vstrfile);
FISECKEY.FILE_DeleteFile(hDevice, vstrDir, vstrfile);
PrintInfo("删除成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//枚举出指定目录的下的所有文件
function FILE_EnmuFile() {
var vstrDir = form1.txtDirName2.value;
try {
//var vstrList = FCOM.FILE_EnmuFile(hDevice, vstrDir);
var vstrList = FISECKEY.FILE_EnmuFile(hDevice, vstrDir);
PrintInfo(vstrList);
PrintInfo("枚举成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//枚举出指定目录的下的所有子目录
function FILE_EnmuDir() {
var vstrDir = form1.txtDirName.value;
try {
//var vstrList = FCOM.FILE_EnmuDir(hDevice, vstrDir);
var vstrList = FISECKEY.FILE_EnmuDir(hDevice, vstrDir);
PrintInfo(vstrList);
PrintInfo("枚举成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//读文件
function FILE_ReadFile() {
var vstrDir = form1.txtDirName2.value;
var vstrfile = form1.txtFileName.value;
var vdwOffSet = form1.txtOffset.value;
var vdwSize = form1.txtDataSize.value;
try {
//var vstrFiledata = FCOM.FILE_ReadFile(hDevice, vstrDir, vstrfile, vdwOffSet, vdwSize);
var vstrFiledata = FISECKEY.FILE_ReadFile(hDevice, vstrDir, vstrfile, parseInt(vdwOffSet), parseInt(vdwSize));
PrintInfo(vstrFiledata);
form1.txtFileData.value = vstrFiledata;
}
catch (e) {
PrintInfo(e.message);
}
}
//写文件
function FILE_WriteFile() {
var vstrDir = form1.txtDirName2.value;
var vstrfile = form1.txtFileName.value;
var vstrData = form1.txtFileData.value;
var vdwOffSet = form1.txtOffset.value;
var vdwSize = form1.txtDataSize.value;
//var str = toExpress("Bva7oELpJfNG0cf8hmFLqDPm5eDAEt0aCy6XJX/OguE=");
try {
//FCOM.FILE_WriteFile(hDevice, vstrDir, vstrfile, vdwOffSet, vdwSize, vstrData);//vstrData
//FCOM.FILE_WriteFile_Base64(hDevice, vstrDir, vstrfile, vdwOffSet, vdwSize, vstrData);//vstrData
FISECKEY.FILE_WriteFile(hDevice, vstrDir, vstrfile, parseInt(vdwOffSet), parseInt(vdwSize), vstrData);
PrintInfo("写成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//获取文件信息
function FILE_GetInfo() {
var vstrDir = form1.txtDirName2.value;
var vstrfile = form1.txtFileName.value;
try {
//var vstrInfo = FCOM.FILE_GetInfo(hDevice, vstrDir, vstrfile);
//var vstrInfo = FISECKEY.FILE_GetInfo(hDevice, vstrDir, vstrfile, "callFILEGetInfo", callFILEGetInfo);
var vstrInfo = FISECKEY.FILE_GetInfo(hDevice, vstrDir, vstrfile);
PrintInfo(vstrInfo);
}
catch (e) {
PrintInfo(e.message);
}
}
//生成对称密钥
function GenKey() {
var viKeyId = form1.txtSymKeyID.value;
var viAlg; //sm1为2 3des为3 des为5 aes为4 sm4为8
var vs = form1.rdSymKeyType;
for (var i = 0; i < vs.length; i++) {
if (vs[i].checked) {
viAlg = vs[i].value;
break;
}
}
try {
FISECKEY.GenKey(hDevice, viAlg, parseInt(viKeyId));
PrintInfo("生成密钥");
}
catch (e) {
PrintInfo(e.message);
}
}
//销毁设备内部存储的指定对称密钥
function DelKey() {
var viKeyId = form1.txtSymKeyID.value;
try {
FISECKEY.DelKey(hDevice, parseInt(viKeyId));
PrintInfo("销毁密钥");
}
catch (e) {
PrintInfo(e.message);
}
}
//导入对称密钥到设备内部并存储
function ImportKey() {
var viKeyId = form1.txtSymKeyID.value;
var vstrKey = form1.txtsymKeyData.value;
var viAlg; //sm1为2 3des为3 des为5 aes为4 sm4为8
var vs = form1.rdSymKeyType;
for (var i = 0; i < vs.length; i++) {
if (vs[i].checked) {
viAlg = vs[i].value;
break;
}
}
try {
FISECKEY.ImportKey(hDevice, viAlg, vstrKey, parseInt(viKeyId));
PrintInfo("导入密钥成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//对称加密运算
function Encrypt() {
var viKeyId = form1.txtSymEnDeKeyId.value;
var vstrIn = form1.txtSymEn.value;
var vstrKey = 0; //form1.symkey.value;
var vstrIv = "12345678123456781234567812345678";
var viAlg; //sm1为2 3des为3 des为5 aes为4 sm4为8
var vs = form1.rdSymEnDeKeyType;
var enData;
for (var i = 0; i < vs.length; i++) {
if (vs[i].checked) {
viAlg = vs[i].value;
break;
}
}
var vWorkMode = 1;
try {
enData = FISECKEY.Encrypt(hDevice, viAlg, parseInt(viKeyId), vWorkMode, vstrIn, vstrIv, vstrKey);
PrintInfo(enData);
}
catch (e) {
PrintInfo(e.message);
}
}
//对称解密运算
function Decrypt() {
var viKeyId = form1.txtSymEnDeKeyId.value;
var vstrChiper = form1.txtSymDe.value;
var vstrKey = 0; //form1.symkey.value;
var vstrIv = "12345678123456781234567812345678";
var viAlg; //sm1为2 3des为3 des为5
var vs = form1.rdSymEnDeKeyType;
var vstrOut;
for (var i = 0; i < vs.length; i++) {
if (vs[i].checked) {
viAlg = vs[i].value;
break;
}
}
var vWorkMode = 1;
try {
vstrOut = FISECKEY.Decrypt(hDevice, viAlg, parseInt(viKeyId), vWorkMode, vstrChiper, vstrIv, vstrKey);
PrintInfo(vstrOut);
}
catch (e) {
PrintInfo(e.message);
}
}
//用户登录
function USER_Login() {
var vstrPin = form1.txtUserPin.value;
try {
FISECKEY.USER_Login(hDevice, vstrPin);
PrintInfo("验证口令成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//管理员登陆
function ADMIN_Login() {
var vstrPin = form1.txtUserPin.value;
try {
//FCOM.ADMIN_Login(hDevice, vstrPin);
FISECKEY.ADMIN_Login(hDevice, vstrPin);
PrintInfo("验证口令成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//用户注销
function USER_Logout() {
var vstrPin = form1.txtUserPin.value;
var vuser = 0;
try {
FISECKEY.USER_Logout(hDevice, vuser);
PrintInfo("用户注销成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//修改用户口令
function USER_ChangeUserPin() {
var vstrOldPin = form1.txtOldPin.value;
var vstrNewPin = form1.txtNewPin.value;
var vstrAgainPin = form1.txtNewPin2.value;
var vflag = 1; //1修改操作员口令
if (vstrNewPin != vstrAgainPin) {
alert("新口令两次输入不一致")
return;
}
try {
FISECKEY.USER_ChangePin(hDevice, vflag, vstrOldPin, vstrNewPin);
PrintInfo("修改操作员口令成功");
}
catch (e) {
PrintInfo(e.message);
}
}
//修改管理员口令
function USER_ChangeAdminPin() {
var vstrOldPin = form1.txtOldPin.value;
var vstrNewPin = form1.txtNewPin.value;
var vstrAgainPin = form1.txtNewPin2.value;
var vflag = 2; //1修改操作员口令2修改管理员口令3解锁
if (vstrNewPin != vstrAgainPin) {
alert("新口令两次输入不一致");
return;
}
try {
//FCOM.USER_ChangePin(hDevice, vflag, vstrOldPin, vstrNewPin);
//FISECKEY.userChangeAdminPin(hDevice, vflag, vstrOldPin, "callUSERChangeAdminPin", callUSERChangeAdminPin);
FISECKEY.USER_ChangePin(hDevice, vflag, vstrOldPin, vstrNewPin);
PrintInfo("修改管理员口令成功");
}
catch (e) {
PrintInfo(e.message);
}
}
function callUSERChangeUnlockPin(data)
{
PrintInfo(data);
}
//解锁操作员口令
function USER_ChangeUnlockPin() {
var vstrAdminPin = form1.Password1.value;
var vstrUserPin = form1.Password2.value;
var vstrAgainPin = form1.Password3.value;
var vflag = 3; //1修改操作员口令2修改管理员口令3解锁
if (vstrUserPin != vstrAgainPin) {
alert("新口令两次输入不一致");
return;
}
try {
//FCOM.USER_ChangePin(hDevice, vflag, vstrAdminPin, vstrUserPin);
//FISECKEY.userChangeUnlockPin(hDevice, vflag, vstrAdminPin, "callUSERChangeUnlockPin", callUSERChangeUnlockPin);
FISECKEY.USER_ChangePin(hDevice, vflag, vstrAdminPin, vstrUserPin);
PrintInfo("解锁操作员口令成功");
}
catch (e) {
PrintInfo(e.message);
}
}
</Script>
<script type="text/javascript" language="javascript">
function findA(obj) {
TagA = obj.getElementsByTagName("a");
if (TagA.length > 0)
return TagA[0];
}
function findContentDIV(obj) {
TagDiv = obj.childNodes;
var arrDiv = new Array;
for (i = 0; i < TagDiv.length; i++) {
var objDiv = TagDiv[i];
var re = /div/i;
var arr = re.exec(objDiv.tagName);
if (arr != null) {
if (arr.index == 0) {
arrDiv.push(objDiv);
}
}
}
return arrDiv;
}
function chShift(o, divGroupID) {
o.style.cursor = "pointer";
var t = o.parentNode;
var tA = t.getElementsByTagName("a");
var tGroup = document.getElementById(divGroupID);
var tGroupDIV = findContentDIV(tGroup);
for (i = 0; i < tA.length; i++) {
tA[i].className = null;
tGroupDIV[i].style.display = "none";
if (tA[i] == findA(o)) {
tA[i].className = "on";
tGroupDIV[i].style.display = "block";
}
}
}
function retInfo_onclick() {
}
function ClearRetInfo() {
var txtRetInfo = form1.retInfo;
form1.mytext.value = "";
}
</script>
<style type="text/css">
ul
{
margin: 0;
padding: 0;
list-style-type: none;
height: 24px;
width: 1012px;
}
ul li
{
float: left;
display: inline;
}
ul a
{
text-decoration: none;
border-top: 1px solid #ddd;
border-bottom: 1px solid #ccc;
border-left: 1px solid #ddd;
border-right: 1px solid #ddd;
display: block;
padding: 5px 0 3px;
margin-left: -1px;
width: 105px;
font-weight: bold;
text-align: center;
line-height: 15px;
color: #11449E;
cursor: hand;
}
a.on, a:hover
{
padding-top: 6px;
padding-bottom: 3px;
width: 76px;
border: 1px solid #ccc;
border-bottom: 0;
background: #DEEBFF;
}
.style2
{
width: 789px;
}
#mytext
{
width: 959px;
height: 147px;
margin-bottom: 2px;
}
#TextHash
{
width: 600px;
height: 100px;
}
#txtSM2PubkeyID
{
width: 50px;
}
#textareaRsaKeyBuf
{
width: 600px;
height: 100px;
}
#TextareaCertData
{
width: 600px;
height: 100px;
}
</style>
</head>
<!--
<body>
<form>
<input type="button" value="test" onclick="test();"/>
<input type="button" value="打开" onclick="opendevice();"/>
<input type="button" value="关闭" onclick="closedevice();"/>
</form>
</body>
-->
<body>
<center>
<form name="form1" action="">
<table>
<tr>
<td>
<span style="font-weight: bold">接口函数返回信息</span>
<br />
<textarea id="mytext"></textarea>
<input type="button" value="清空" onclick="ClearRetInfo()" />
<br />
</td>
</tr>
<tr>
<td class="style2">
<div>
<ul>
<li onclick="javascript:chShift(this,'divGroup')"><a class="on">设备</a></li>
<li onclick="javascript:chShift(this,'divGroup')"><a>用户管理</a></li>
<li onclick="javascript:chShift(this,'divGroup')"><a>对称算法</a></li>
<li onclick="javascript:chShift(this,'divGroup')"><a>RSA</a></li>
<li onclick="javascript:chShift(this,'divGroup')"><a>ECC</a></li>
<li onclick="javascript:chShift(this,'divGroup')"><a>HASH</a></li>
<li onclick="javascript:chShift(this,'divGroup')"><a>证书</a></li>
<li onclick="javascript:chShift(this,'divGroup')"><a>文件</a></li>
<li onclick="javascript:chShift(this,'divGroup')"><a>随机数</a></li>
<li onclick="javascript:chShift(this,'divGroup')"><a>说明</a></li>
</ul>
</div>
</td>
</tr>
<tr>
<td class="style2">
<div id="divGroup">
<div>
<table>
<tr>
<td align="left">
<br />
<span style="font-weight: bold">设备类型</span>
<br />
<input type="radio" name="devtype" value="4" checked="checked" />智能密码钥匙
<input type="radio" name="devtype" value="5" />K+U设备
<br />
<hr />
<span style="font-weight: bold">根据设备索引打开设备</span>
<br />
设备索引:
<input type="text" id="devid" name="devid" value="0" />
<span>0-15</span>
<input type="button" onclick="opendevice()" value="打开设备" />
<hr />
<span style="font-weight: bold">枚举设备</span>
<br />
<input type="button" onclick="EnumDevByName()" value="枚举设备名称" />
<input type="button" onclick="EnumDevBySerial()" value="枚举设备序列号" />
<input type="button" onclick="EnumDevByArray()" value="枚举序列号与名称" />
<br />
<hr />
<span style="font-weight: bold">根据设备序列号打开设备</span>
<br />
设备序列号:
<input type="text" id="txtDeviceSerial" />
<input type="button" onclick="OpenDevBySerial()" value="打开设备" />
<br />
<hr />
<span style="font-weight: bold">根据设备名称打开设备</span>
<br />
名称:
<input type="text" id="txtDeviceName" />
<br />
索引:
<input type="text" id="txtDeviceID2" value="0" />
<span>0-15</span>
<input type="button" onclick="OpenDeviceByName()" value="打开设备" />
<br />
<hr />
<span style="font-weight: bold">修改设备名称</span>
<br />
设备名称:
<input type="text" id="DeviceName2" />
<input type="button" value="修改设备名称" onclick="SetDeviceName()" />
<input type="button" value="获取设备名称" onclick="GetDeviceName()" />
<input type="button" value="获取密钥信息" onclick="GetKeyMask()" />
<hr />
<span style="font-weight: bold">关闭设备</span>
<br />
<input type="button" id="btnCloseDevice" value="关闭设备" onclick="closedevice()" />
<br />
</td>
</tr>
</table>
</div>
<div style="display: none">
<table>
<tr>
<td align="left">
<br />
<span style="font-weight: bold">用户登录</span>
<br />
PIN码
<input type="password" id="txtUserPin" />
<br />
<input type="button" value="操作员登录" onclick="USER_Login()" />
<input type="button" value="管理员登录" onclick="ADMIN_Login()" />
<hr />
<span style="font-weight: bold">注销</span>
<br />
<input type="button" value="注销" onclick="USER_Logout()" />
<hr />
<span style="font-weight: bold">修改密码</span>
<br />
旧PIN码
<input type="password" id="txtOldPin" />
<br />
新PIN码
<input type="password" id="txtNewPin" />
<br />
重复新PIN码
<input type="password" id="txtNewPin2" />
<br />
<input type="button" id="btnChangeOpPin" value="修改操作员PIN码" onclick="USER_ChangeUserPin()" />
<input type="button" id="btnChangeAdminPin" value="修改管理员PIN码" onclick="USER_ChangeAdminPin()" />
<hr />
<span style="font-weight: bold">解锁操作员密码</span>
<br />
操作员密码:
<input type="password" id="Password1" />
<br />
新PIN码
<input type="password" id="Password2" />
<br />
重复新PIN码
<input type="password" id="Password3" />
<br />
<input type="button" id="btnUnlockOpPin" value="解锁操作员PIN码" onclick="USER_ChangeUnlockPin()" />
<br />
<br />
</td>
</tr>
</table>
</div>
<div style="display: none">
<table>
<tr>
<td align="left">
<br />
<span style="font-weight: bold">密钥管理</span>
<br />
密钥序号:
<input type="text" id="txtSymKeyID" size="5" value="1" />
<br />
密钥类型:
<input type="radio" name="rdSymKeyType" value="2" checked="checked" />
SM1&nbsp&nbsp
<input type="radio" name="rdSymKeyType" value="5" />
DES&nbsp&nbsp
<input type="radio" name="rdSymKeyType" value="3" />
3DES&nbsp&nbsp
<br />
密钥数据:
<input type="text" id="txtsymKeyData" size="90" value="QLsS3WqCc4Z/NSnTVLSgJg==" />
<input type="button" value="生成对称密钥" onclick="GenKey()" />
<input type="button" value="导入对称密钥" onclick="ImportKey()" />
<input type="button" value="销毁对称密钥" onclick="DelKey()" />
<hr />
<span style="font-weight: bold">加解解密</span>
<br />
明文数据:
<input type="text" size="90" id="txtSymEn" value="/+7dzLuqmYh3ZlVEMyIRAA==" />
<br />
密文数据:
<input type="text" size="90" id="txtSymDe" />
<br />
解密数据:
<input type="text" size="90" id="txtSymEn2" />
<br />
密钥序号:
<input type="text" id="txtSymEnDeKeyId" size="5" value="1" />
<br />
密钥类型:
<input type="radio" name="rdSymEnDeKeyType" value="2" checked="checked" />
SM1&nbsp&nbsp
<input type="radio" name="rdSymEnDeKeyType" value="5" />
DES&nbsp&nbsp
<input type="radio" name="rdSymEnDeKeyType" value="3" />
3DES&nbsp&nbsp
<br />
<input type="button" value="对称加密" onclick="Encrypt()" />
<input type="button" value="对称解密" onclick="Decrypt()" />
<br />
<br />
</td>
</tr>
</table>
</div>
<div style="display: none">
<table>
<tr>
<td align="left">
<br />
<span style="font-weight: bold">生成密钥</span>
<br />
密钥序号:
<input type="text" id="txtRsaKeyId" size="5" value="1" />
<br />
模长:
<input type="radio" name="rdRsaModeLen" value="1024" checked="checked" />
1024&nbsp&nbsp
<input type="radio" name="rdRsaModeLen" value="2048" />
2048&nbsp&nbsp
<br />
<input type="button" value="生成RSA密钥" onclick="GenRSAKeyPair()" />
<!--<input type="button" value="导出RSA密钥" onclick="ExportRSAKeyBase64()" />
<input type="button" value="导出RSA密钥P8格式" onclick="ExportRSAKeyP8Base64()" />
<input type="button" value="导入RSA密钥到密钥容器" onclick="ImportRSAKeyIntoContainer()" /> -->
<input type="button" value="销毁RSA密钥" onclick="DelRSAKeyPair()" />
<hr />
<span style="font-weight: bold">导入密钥</span>
<br />
<textarea id="TextareaRsaKeyBuf">-----BEGIN-----
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJd3WqoFjOjfYnFhzfV/CahKWkmNcLlJ
A0Zna4axBMNZxaHwzYbnLs452fOQAccVmuR2dD4T3SRRyjn1ZRUB3tyY81IdYO+rVKx/g10jZYqfXllH
t03Eget6ggjvIe0CFjysjamkjFEcvTBk3b58OlUm+f1rxPA4HNw2pzbU1MDBAgMBAAECgYAxHd8kq1AaY
/YEVnb3WQ7Ep/fHSjp3mxmYxwizUMv+nSndbbz4NheTgGcQ+G3bJUJpO5BOYRqhIHS3fsAco9Kkrq5XDke
NzB3jLa5qY3r60xDivgA7X3lJZfR+LLBXUyLgcq7cArBu/5JLUZQUMjkk3uHIXu9LXCqX9pBP6KyCEQJBAMW
72XdDBnBp8tH8oOSFef15BiEhTiPFpZnCUrSOzuWJJm9dFA16qxaiy5fPbLrW/UJUpE0udSiOOIUpXhV8FV8
CQQDEGUmQ4nORy8BtwpQiSSyN5y6kEZK8ezbm5MN3ECd3KHv79RfcNQsQo8di6hytbIJXuYvM0vjHTmiz2WoC
ab3fAkBkqeFoCcM5b3ai2I3ASQN1uysXqrDxHSnVQUyBh0JlMJFUmHog8pYvC+nB+2NLKy/7mMOcV05luyGjC
RBQt77ZAkBHhCVlNoEJcfJ61RSrMF6UXfSPl20ZWiJasKFsobKS7WvSJr+N6rZfWiuUMmdFBCbBEYUfrO1X2o
uq06aqvJ+nAkAyrLBkocEcJsK8t3IEf7OqgkPtfMYU5nv6GyVa4338z+ezHyRUY+RAJ6DJVePTp9HsIMyhYqZ
LUbupbMxubzaL
-----END-----</textarea>
<br />
密钥序号:
<input type="text" id="txtImportRsaKeyId" size="5" value="1" />
<br />
模长:
<input type="radio" name="rdImportRsaModeLen" value="1024" checked="checked" />
1024&nbsp&nbsp
<input type="radio" name="rdImportRsaModeLen" value="2048" />
2048&nbsp&nbsp
<br />
<!--<input type="button" value="导入公钥" onclick="ImportRSAPubKeyBase64()" /> -->
<input type="button" value="导入私钥" onclick="ImportRSAPriKeyBase64()" />
<hr />
<span style="font-weight: bold">RSA运算</span>
<br />
明文数据:
<input type="text" id="txtRsaInbuf" size="90" value="/+7dzLuqmYh3ZlVEMyIRAA==" />
<br />
密文数据:
<input type="text" id="txtCipherBuf" size="90" />
<br />
解密数据:
<input type="text" id="txtOutbuf" size="90" /> 密钥序号:
<input type="text" id="txtEnDeRsaKeyId" size="5" value="1" />
<br />
<input type="button" value="RSA加密" onclick="RSAEncrypt()" />
<input type="button" value="RSA解密" onclick="RSADecrypt()" />
<input type="button" value="RSA签名" onclick="RSASign()" />
<input type="button" value="RSA验签" onclick="RSAVerify()" />
<br />
</td>
</tr>
</table>
</div>
<div style="display: none">
<table>
<tr>
<td align="left">
<br />
<span style="font-weight: bold">生成密钥</span>
<br />
密钥序号:
<input type="text" id="txtECCKeyID" value="1" size="5" />
<br />
<input type="button" onclick="GenECCKeypair()" value="生成ECC密钥" />
<input type="button" onclick="ExportECCKeypair()" value="导出ECC密钥" />
<input type="button" onclick="DelECCKeypair()" value="删除ECC密钥" />
<hr />
<span style="font-weight: bold">导入密钥</span>
<br />
密钥数据:
<textarea rows="5" cols="90" id="txtECCKeyData">MIICBgIBADCB7QYIKoEcgUUBgi0wgeACAQEwLAYHKoZIzj0BAQIhAIVC1p5MBE8Y6LkkNb9v995FcoORXEVRfXIu24sI8d/DMEQEIHh5aLT6MsP9JBeELnO7/v8vPISLaDHX4OxlIos5N+SYBCBj5MbTsjsMhJz4QkFIS/5I9h1ZpbFroG5uEtHaJ8UkmgRBBEId69YbYuq2dGQ068PMMV4yIgs7rdUL3ExObBR/7dQ9BoBRK8u0LAfUc0nSFTtwxOXX/fy/o26hqFhBueRuCaICIQCFQtaeTARPGOi5JDW/b/fdKXcgYwSFYo1a507nwy55twIBAQSCAQ8wggELAgEBBCBy9u84dT/8Q1X7bMwgo1gMRNwTukSnG/K3/gL02O/BhaCB4zCB4AIBATAsBgcqhkjOPQEBAiEAhULWnkwETxjouSQ1v2/33kVyg5FcRVF9ci7biwjx38MwRAQgeHlotPoyw/0kF4Quc7v+/y88hItoMdfg7GUiizk35JgEIGPkxtOyOwyEnPhCQUhL/kj2HVmlsWugbm4S0donxSSaBEEEQh3r1hti6rZ0ZDTrw8wxXjIiCzut1QvcTE5sFH/t1D0GgFEry7QsB9RzSdIVO3DE5df9/L+jbqGoWEG55G4JogIhAIVC1p5MBE8Y6LkkNb9v990pdyBjBIVijVrnTufDLnm3AgEB</textarea>
<br />
私钥数据:
<textarea rows="3" cols="90" id="txtECCPriKeyData">MD4CAQAwDAYIKoEcz1UBgi0FAAQrMCkCAQEEIALAfYbWeMoWIO5dIUMHB4y8XoXIoJUfoNkWVSrYY0B6oAIFAA==</textarea>
<br />
<br />
公钥数据:
<textarea rows="3" cols="90" id="txtECCPubKeyData">MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAElxXN23MgIQI3TVIkNBlyVLjRObf3PLySCmynCY5Z/d+1ZfiXObNdCDfYrcubaHbpUXpFqTiNNw78j/Urwv2PBw==</textarea>
<br />
密钥序号:
<input type="text" id="txtECCKeyID1" value="1" size="5" />
<br />
<!--<input type="button" value="导入私钥" onclick="ImportECCKeypair()" />
<input type="button" value="导入公钥" onclick="ImportECCKeypair1()" />-->
<input type="button" value="导入密钥对" onclick="ImportECCKeypair2()" />
<hr />
<span style="font-weight: bold">SM2运算</span> <span style="color: #FF0000;">(SM2签名内部没有进行哈希运算,需要手动执行)</span>
<br />
数据明文:
<input type="text" id="txtECCInBuf" size="90" value="/+7dzLuqmYh3ZlVEMyIRAA==" />
<br />
数据密文:
<input type="text" id="txtECCCipherBuf" size="90" />
<br />
解密数据:
<input type="text" id="txtECCOutBuf" size="90" />
<br />
密钥序号:
<input type="text" id="txtEccEnDeKeyID" value="1" size="5" />
<br />
<input type="button" onclick="ECCEncrypt()" value="ECC加密">
<input type="button" onclick="ECCDecrypt()" value="ECC解密">
<input type="button" value="ECC签名" onclick="ECCSign()" />
<input type="button" value="ECC验签" onclick="ECCVerify()" />
<input type="button" onclick="ECCEncryptDer()" value="ECC加密(DER)">
<input type="button" onclick="ECCDecryptDer()" value="ECC解密(DER)">
<br />
</td>
</tr>
</table>
</div>
<div style="display: none">
<table>
<tr>
<td align="left">
<br />
<span style="font-weight: bold">哈希算法</span> <span style="color: #FF0000;">(输入数据采用base64编码格式)</span>
<br />
输入数据:
<textarea id="TextHash"></textarea>
<br />
<input type="button" value="SHA1运算" onclick="Hash()" />
<br />
<br />
<br />
<br />
SM2密钥:
<input type="text" id="txtSM2PubkeyID" value="255" />
(0-31:使用该密钥号公钥初始化255:不使用SM2公钥初始化)
<br />
<input type="button" value="SM3运算 " onclick="SM3Data()" />
</td>
</tr>
</table>
</div>
<div style="display: none">
<table>
<tr>
<td align="left">
<br />
<span style="font-weight: bold">枚举容器</span>
<br />
<input type="button" value="枚举容器" onclick="ContainerEnum()" />
<br />
<br />
容器名称:
<input type="text" id="txtContainerName" size="40" />
<input type="button" value="销毁容器" onclick="DelContainer()" />
<hr />
<span style="font-weight: bold">导入证书</span> <span style="color: #FF0000;">(证书数据必须为PEM编码格式)</span>
<br />
容器名称:
<input type="text" id="txtContainerName2" size="40" />
<br />
证书类型:
<input type="radio" name="rdCertType" value="1" checked="checked" />
加密证书
<input type="radio" name="rdCertType" value="2" />
签名证书
<br />
证书数据:
<textarea id="TextareaCertData"></textarea>
<br />
<input type="button" value="导入证书" onclick="ContainerWriteCert()" />
<input type="button" value="导出证书" onclick="ContainerReadCert()" />
<input type="button" value="获取信息" onclick="GetSerialAndSubjects()" />
<hr />
<span style="font-weight: bold">导出证书序列号</span>
<br />
容器名称:
<input type="text" id="txtContainerName3" size="40" />
证书类型:
<input type="radio" name="rdCertType1" value="1" checked="checked" />
加密证书
<input type="radio" name="rdCertType1" value="2" />
签名证书
<br />
<input type="button" id="btnExportKeyID" value="导出密钥序号" onclick="ContainerReadCertSerial()" />
<br />
</td>
</tr>
</table>
</div>
<div style="display: none">
<table>
<tr>
<td align="left">
<br />
<span style="font-weight: bold">目录</span>
<br />
目录名称:
<input type="text" id="txtDirName" value="\root" />
目录权限:
<input type="text" id="txtDirPerm" value="0" />
<br />
<input type="button" value="枚举目录" onclick="FILE_EnmuDir()" />
<input type="button" value="创建目录" onclick="FILE_CreateDir()" />
<input type="button" value="删除目录" onclick="FILE_DeleteDir()" />
<hr />
<span style="font-weight: bold">文件</span>
<br />
目录名称:
<input type="text" id="txtDirName2" value="\root" />
<br />
文件名称:
<input type="text" id="txtFileName" />
文件权限:
<input type="text" id="txtFilePerm" value="0" />
文件大小:
<input type="text" id="txtFileSize" />
<div>
偏移地址:
<input type="text" id="txtOffset" value="0" />
数据大小:
<input type="text" id="txtDataSize" value="8" />
</div>
文件数据:
<input type="text" id="txtFileData" size="90" value="1234567812345678" />
<input type="button" value="枚举文件" style="width: 110px" onclick="FILE_EnmuFile()" />
<br />
<input type="button" value="创建文件" style="width: 110px" onclick="FILE_CreateFile()" />
<input type="button" value="删除文件" style="width: 110px" onclick="FILE_DeleteFile()" />
<br />
<input type="button" value="读文件" style="width: 110px" onclick="FILE_ReadFile()" />
<input type="button" value="写文件" style="width: 110px" onclick="FILE_WriteFile()" />
<br />
<input type="button" value="文件系统格式化" style="width: 110px" onclick="FILE_Init()" />
<input type="button" value="获取文件信息" style="width: 110px" onclick="FILE_GetInfo()" />
<br />
</td>
</tr>
</table>
</div>
<div style="display: none">
<table>
<tr>
<td align="left">
<br />
<span style="font-weight: bold">生成随机数</span>(随机数长度应大于1)
<div>
长度:
<input type="text" id="txtRandLen" size="8" value="16" />
<input type="button" value="生成随机数" onclick="GenRandom()" />
</div>
</td>
</tr>
</table>
</div>
<div style="display: none">
<table>
<tr>
<td align="left">
<br />
<span style="font-size: 20px; font-weight: bold">使用方法</span>
<br />
(1)将fmcom.dllFM_SIC_DLL.dll拷贝到电脑指定目录
<br />
(2)执行命令 regsvr32 路径\fmcom.dll
<br />
<br />
<br />
<span style="font-size: 20px; font-weight: bold">需要操作员权限的操作</span>
<br />
<span style="font-weight: bold">一、对称算法</span>
<br />
(1)生成密钥
<br />
(2)导入密钥
<br />
(3)销毁密钥
<br />
(4)对称加密
<br />
(5)对称解密
<br />
<span style="font-weight: bold">二、非对称算法</span>
<br />
(1)生成密钥
<br />
(2)导入密钥
<br />
(3)销毁密钥
<br />
(4)对称加密
<br />
(5)对称解密
<br />
(6)签名
<br />
(7)验证
<br />
<span style="font-weight: bold">三、证书</span>
<br />
(1)枚举容器
<br />
(2)销毁容器
<br />
(3)导入证书
<br />
(4)导出证书
<br />
<span style="font-weight: bold">四、文件</span>
<br />
(1)枚举目录
<br />
(2)创建目录
<br />
(3)删除目录
<br />
(4)枚举文件
<br />
(5)创建文件
<br />
(6)删除文件
<br />
(7)读文件
<br />
(8)写文件
<br />
</td>
</tr>
</table>
</div>
</div>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>