bouncycastle JAVA实现SM3算法
生活随笔
收集整理的這篇文章主要介紹了
bouncycastle JAVA实现SM3算法
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
bouncycastle JAVA實(shí)現(xiàn)SM3算法(國(guó)密3)
- bouncycastle 早在1.5版本就已經(jīng)支持SM3算法
bouncycastle 早在1.5版本就已經(jīng)支持SM3算法
下面是一個(gè)簡(jiǎn)單的實(shí)例
先引入maven
<dependency><groupId>org.bouncycastle</groupId><artifactId>bcprov-jdk15on</artifactId><version>1.69</version></dependency>下面是實(shí)現(xiàn)實(shí)例
SM3Digest sm3Digest=new SM3Digest(); byte[] srcData = "abc".getBytes(); sm3Digest.update(srcData,0,srcData.length); byte[] hash = new byte[sm3Digest.getDigestSize()]; sm3Digest.doFinal(hash, 0); System.out.println("sm3加密11111:"+SM3.byteArrayToHexString(hash)); //假如輸出為66C7F0F462EEEDD9D1F2D46BDC10E4E24167C4875CF2F7A2297DA02B8F4BA8E0就說(shuō)明符合SM3算法要求private static char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8','9', 'A', 'B', 'C', 'D', 'E', 'F'}; public static String byteArrayToHexString(byte[] b) {StringBuffer resultSb = new StringBuffer();for (int i = 0; i < b.length; i++) {resultSb.append(byteToHexString(b[i]));}return resultSb.toString();}private static String byteToHexString(byte b) {int n = b;if (n < 0)n = 256 + n;int d1 = n / 16;int d2 = n % 16;return ""+hexDigits[d1] + hexDigits[d2];}總結(jié)
以上是生活随笔為你收集整理的bouncycastle JAVA实现SM3算法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: icem搅拌器网格划分_搅拌器研究所的第
- 下一篇: Linux信号量详解