Skip to content

Commit

Permalink
fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Feb 26, 2021
1 parent ffc5b98 commit cd6d28e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
38 changes: 36 additions & 2 deletions docs/crypto/国密算法工具-SmUtil.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,49 @@ String x = "9EF573019D9A03B16B0BE44FC8A5B4E8E098F56034C97B312282DD0B4810AFC3";
String y = "CC759673ED0FC9B9DC7E6FA38F0E2B121E02654BF37EA6B63FAF2A0D6013EADF";

// 数据和ID此处使用16进制表示
String dataHex = "434477813974bf58f94bcf760833c2b40f77a5fc360485b0b9ed1bd9682edb45";
String idHex = "31323334353637383132333435363738";
String data = "434477813974bf58f94bcf760833c2b40f77a5fc360485b0b9ed1bd9682edb45";
String id = "31323334353637383132333435363738";

final SM2 sm2 = new SM2(privateKeyHex, x, y);
// 生成的签名是64位
sm2.usePlainEncoding();

final String sign = sm2.signHex(data, id);
// true
boolean verify = sm2.verifyHex(data, sign)
```

5. 使用私钥D值签名

```java
//需要签名的明文,得到明文对应的字节数组
byte[] dataBytes = "我是一段测试aaaa".getBytes();
//指定的私钥
String privateKeyHex = "1ebf8b341c695ee456fd1a41b82645724bc25d79935437d30e7e4b0a554baa5e";

// 此构造从5.5.9开始可使用
final SM2 sm2 = new SM2(privateKeyHex, null, null);
sm2.usePlainEncoding();
byte[] sign = sm2.sign(dataBytes, null);
```

6. 使用公钥Q值验证签名

```java
//指定的公钥
String publicKeyHex ="04db9629dd33ba568e9507add5df6587a0998361a03d3321948b448c653c2c1b7056434884ab6f3d1c529501f166a336e86f045cea10dffe58aa82ea13d725363";
//需要加密的明文,得到明文对应的字节数组
byte[] dataBytes = "我是一段测试aaaa".getBytes();
//签名值
String signHex ="2881346e038d2ed706ccdd025f2b1dafa7377d5cf090134b98756fafe084dddbcdba0ab00b5348ed48025195af3f1dda29e819bb66aa9d4d088050ff148482a";

final SM2 sm2 = new SM2(null, ECKeyUtil.toSm2PublicParams(publicKeyHex));
sm2.usePlainEncoding();

// true
boolean verify = sm2.verify(dataBytes, HexUtil.decodeHex(signHex));
```

### 摘要加密算法SM3

```java
Expand Down
3 changes: 2 additions & 1 deletion docs/db/数据源工厂-DsFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ DataSource ds = DSFactory.get();
//自定义数据库Setting,更多实用请参阅Hutool-Setting章节
Setting setting = new Setting("otherPath/other.setting");
//获取指定配置,第二个参数为分组,用于多数据源,无分组情况下传null
DataSource ds = DSFactory.get(setting, null);
// 注意此处DSFactory需要复用或者关闭
DataSource ds = DSFactory.create(setting).getDataSource();
```

### 3. 多数据源
Expand Down
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ <h4>需求分析,项目沟通,提供解决方案</h4>
<div class="col-md-4">
<div class="person">
<img src="https://cdn.jsdelivr.net/gh/looly/hutool-site/images/team/monkey.jpg" alt="" class="img-responsive">
<h3>monkey</h3>
<h3>Monkey</h3>
<h4>什么是技术的本质</h4>
<p>一名无缘985,日常996的程序员。三爱:爱分享、爱开车、爱研究技术。三不爱:不爱加班、不爱旅游、不爱男人<br>&nbsp;</p>
<ul class="social">
Expand Down Expand Up @@ -485,6 +485,9 @@ <h2>友情链接</h2>
<div class="col-md-2 friend">
<a target="_blank" href="https://opsli.com/"><img src="https://www.opsli.com/logo.png"></a>
</div>
<div class="col-md-2 friend">
<a target="_blank" href="https://www.eova.cn/"><img src="https://www.eova.cn/favicon.ico"><small>EOVA快速开发</small></a>
</div>
</div>
</div>
<!-- END fh5co-friends -->
Expand Down

0 comments on commit cd6d28e

Please sign in to comment.