恒生国密接口。可获取crypto实例
参数
Object object
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| publicKey | string | 无 | 否 | 公钥 |
| privateKey | string | 无 | 否 | 私钥 |
| success | function | 无 | 否 | 接口调用成功的回调函数 |
| fail | function | 无 | 否 | 接口调用失败的回调函数 |
| complete | function | 无 | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
实例的方法
crypto.generateKeyPair()
生成国密密钥对,如果初始化实例时不传入参publicKey和privateKey,可通过此接口自动生成,此接口调用后将以生成的密钥为准,此时实例创建时传入的密钥将无效。
crypto.getKeyPair(function)
获取国密密钥对
function的回调参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| publicKey | string | 公钥 |
| privateKey | string | 私钥 |
crypto.sign(params,function)
国密数字签名,需要的入参如下
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| plainText | string | 无 | 是 | 明文 |
function回调参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| signature | string | 返回数字签名 |
crypto.verify(params,function)
国密数字验签,需要的入参如下
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| plainText | string | 无 | 是 | 明文 |
| signature | string | 无 | 是 | 数字签名 |
function回调参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| result | int | 1:成功,0:失败,其他数值-错误 |
crypto.encode(params,function)
国密加密,需要的入参如下
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| plainText | string | 无 | 是 | 明文 |
| type | string | 无 | 否 | 国密加密类型,可选值sm2或sm4 ,默认值是sm2 |
| password | string | 无 | 否(如果type取值sm4则为必填) | 加密密码 |
function回调参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| cipherText | string | 返回密文 |
crypto.decode(params,function)
国密解密,需要的入参如下
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| type | string | 无 | 否 | 国密解密类型,可选值sm2、sm3或sm4 ,默认值是sm2 |
| plainText | string | 无 | 否(如果type取值sm3则为必填) | 明文 |
| cipherText | string | 无 | 否(如果type取值sm2或sm4则为必填) | 密文 |
| password | string | 无 | 否(如果type取值sm4则为必填) | 加密密码 |
function回调参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| plainText | string | 返回明文(仅当type为sm2或sm4时返回该字段) |
| digest | string | (仅当type为sm3时返回该字段)返回消息摘要 |
示例代码
let that = this; |
注意事项
需要在APP的config.js配置文件中做以下配置:
module.exports = { |