This commit is contained in:
parent
08e9b2326e
commit
745eb89b4e
File diff suppressed because one or more lines are too long
|
|
@ -41,7 +41,7 @@ if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {};
|
|||
* </ul>
|
||||
* </p>
|
||||
*/
|
||||
KJUR.crypto.ECDSA = function(params) {
|
||||
KJUR.crypto.ECDSA =function(params) {
|
||||
var curveName = "secp256r1"; // curve name default
|
||||
var ecparams = null;
|
||||
var prvKeyHex = null;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ function SM2Cipher(cipherMode) {
|
|||
if (typeof (cipherMode) != 'undefined') {
|
||||
this.cipherMode = cipherMode
|
||||
} else {
|
||||
this.cipherMode = SM2CipherMode.C1C2C3//默认0
|
||||
this.cipherMode = SM2CipherMode.C1C2C3//Ĭ<EFBFBD><EFBFBD>0
|
||||
}
|
||||
}
|
||||
SM2Cipher.prototype = {
|
||||
|
|
@ -83,6 +83,7 @@ SM2Cipher.prototype = {
|
|||
var c3 = new Array(32);
|
||||
this.Dofinal(c3);
|
||||
var hexString = bytesToHex(c1.getEncoded(false)) + bytesToHex(data) + bytesToHex(c3);
|
||||
console.log(this.cipherMode )
|
||||
if (this.cipherMode == SM2CipherMode.C1C3C2) {
|
||||
hexString = bytesToHex(c1.getEncoded(false)) + bytesToHex(c3) + bytesToHex(data)
|
||||
}
|
||||
|
|
@ -125,7 +126,7 @@ SM2Cipher.prototype = {
|
|||
|
||||
|
||||
GetBigIntegerByteArray : function(bi) {
|
||||
//BigIntger.toByteArray()转为有符号的二进制,此方法转为无符号的二进制才可以与后台Java端的加解密等效
|
||||
//BigIntger.toByteArray()תΪ<EFBFBD>з<EFBFBD><EFBFBD>ŵĶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><EFBFBD>˷<EFBFBD><EFBFBD><EFBFBD>תΪ<EFBFBD><EFBFBD><EFBFBD>ŵĶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʋſ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨Java<EFBFBD>˵ļӽ<EFBFBD><EFBFBD>ܵ<EFBFBD>Ч
|
||||
var tmpd = [];
|
||||
if (bi == null) {
|
||||
return tmpd;
|
||||
|
|
@ -155,7 +156,7 @@ window.SM2CipherMode = {
|
|||
|
||||
function SM2CipherUtil() {
|
||||
var cipher = new SM2Cipher();
|
||||
//获取公钥与私钥
|
||||
//<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>Կ<EFBFBD><EFBFBD>˽Կ
|
||||
this.sm2GengenerateKeys = function() {
|
||||
var ec = new KJUR.crypto.ECDSA({"curve": "sm2"});
|
||||
var keypair = ec.generateKeyPairHex();
|
||||
|
|
@ -164,7 +165,6 @@ function SM2CipherUtil() {
|
|||
this.sm2Encrypt = function(publicKey, text) {
|
||||
var userKey = cipher.CreatePoint(publicKey);
|
||||
var msgData = strToUtf8Bytes(text);
|
||||
//返回16进制字符串
|
||||
return cipher.Encrypt(userKey, msgData);
|
||||
};
|
||||
this.sm2Decrypt = function(privateKey, cipherText) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//二进制数组转16进掉
|
||||
//???????????16????
|
||||
function bytesToHex(arr) {
|
||||
var str = "";
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
|
|
@ -7,7 +7,7 @@ function bytesToHex(arr) {
|
|||
return str;
|
||||
};
|
||||
|
||||
//16进掉转二进制数组
|
||||
//16???????????????
|
||||
function hexToBytes(str) {
|
||||
var arr = [];
|
||||
var hexStrLength = str.length;
|
||||
|
|
@ -17,7 +17,7 @@ function hexToBytes(str) {
|
|||
return arr;
|
||||
};
|
||||
|
||||
//字符转UTF-8的二进制数组
|
||||
//????UTF-8???????????
|
||||
function strToUtf8Bytes(str) {
|
||||
var bytes = new Array();
|
||||
var len, c;
|
||||
|
|
@ -43,7 +43,7 @@ function strToUtf8Bytes(str) {
|
|||
return bytes;
|
||||
};
|
||||
|
||||
//二进制数组转UTF-8的字符
|
||||
//???????????UTF-8?????
|
||||
function bytesToUtf8Str(arr) {
|
||||
try {
|
||||
var str = '', _arr = arr;
|
||||
|
|
@ -63,7 +63,7 @@ function bytesToUtf8Str(arr) {
|
|||
}
|
||||
return str;
|
||||
} catch(e) {
|
||||
alert("转UTF8出错,非UTF8的二进制数组");
|
||||
alert("?UTF8??????UTF8???????????");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue