# gm-ukey2

> 使用新版驱动，websocket连接

Latest version **1.0.1** (published 2023-09-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install gm-ukey2
pnpm add gm-ukey2
yarn add gm-ukey2
bun add gm-ukey2
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-09-18 |
| First published | 2023-09-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | chilamz001 |

## Links

- npm: https://www.npmjs.com/package/gm-ukey2
- npm.io page: https://npm.io/package/gm-ukey2

## Recent versions

- 1.0.1 (latest) — 2023-09-18

## README

# gm-ukey2

国密证书UkeySDK



### 安装

##### 使用npm

```
$ npm install gm-ukey2 --save
```


### 使用

##### 使用import或者require引入

```
import GMUkey from 'gm-ukey2'

// const GMUkey = require('gm-ukey2')
```



##### 异步调用接口

```
GMUKey.version().then(function (res) {
    console.log(res)
}).catch(function (error) {
    console.log(error)
})
```



##### 同步调用接口

```
const res = await GMUKey.version()
console.log(res)
```



### 示例

##### 获取版本

```
GMUKey.version((res) => {
    console.log(res)
})
```



##### 生成随机数

```
GMUKey.random({len: 16}, (res) => {
    console.log(res)
})
```



##### sm2消息签名

```
GMUKey.sm2sign(
    {
    pin: '123456', 
    msg: 'message'
    }, (res) => {
        console.log(res)
    }
)
```
##### sm2消息校验

```
GMUKey.sm2verify(
    {
    pin: '123456', 
    msg: 'message',
    signature: sm2Sign,
    }, (res) => {
        console.log(res)
    }
)
```



##### sm2文件签名

```
GMUKey.sm2signFile(
    {
    pin: '123456',
    path: 'D:\\a.txt',
    ida:'1234567812345678'
    }, (res) => {
        console.log(res)
    }
)
```



##### sm2文件校验

```
GMUKey.sm2verifyFile(
    {
    pin: '123456',
    path: 'D:\\a.txt',
    signature: sm2FileSign,
    ida:'1234567812345678'
    }, (res) => {
        console.log(res)
    }
)

```



##### 字符串对称加密 257(SM1加密)，1025(SM4加密)
```
GMUKey.encrypt(
    {
    pin: '123456', 
    msg: 'message',
    key:'1234567812345678',
    alg:257
    }, (res) => {
        console.log(res)
    }
)
```



##### 字符串对称解密

```
GMUKey.decrypt(
    {
    pin: '123456', 
    msg: 'encrypted',
    key:'1234567812345678',
    alg:257
    }, (res) => {
        console.log(res)
    }
)
```



##### 读取key证书信息

```
GMUKey.certparse(
    {
    pin: '123456', 
    bsign: 1,
    }, (res) => {
        console.log(res)
    }
)
```



##### 导出证书

```
GMUKey.certexport(
    {
    pin: '123456',
    bsign: 1
    }, (res) => {
        console.log(res)
    }
)
```



##### PIN码校验

```
GMUKey.pinverify(
    {
    pin: '111111',
    }, (res) => {
        console.log(res)
    }
)
```



##### 更改PIN码

```
GMUKey.pinchange(
    {
    pin: '111111',
    newpin: '111111'
    }, (res) => {
        console.log(res)
    }
)
```



##### 生成P7(SM2WithSM3)

```
GMUKey.genp7(
    {
    pin: '123456',
    path: 'D:\\a.txt',
    section:'0,10',
    ida: '1234567812345678'
    }, (res) => {
        console.log(res)
    }
)
```

---
_Source: https://npm.io/package/gm-ukey2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
