资源简介
java 国密算法sm2、sm3 详细使用参考:https://blog.csdn.net/weixin_30512027/article/details/86013878
代码片段和文件信息
package com.lysj.property.core.util.sm;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.objectInputStream;
import java.io.objectOutputStream;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Arrays;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECPoint;
/**
* SM2公钥加密算法实现 包括 -签名验签 -密钥交换 -公钥加密私钥解密
*
* @author Potato
*
*/
public class SM2 {
private static BigInteger n = new BigInteger(
“FFFFFFFE“ + “FFFFFFFF“ + “FFFFFFFF“ + “FFFFFFFF“ + “7203DF6B“ + “21C6052B“ + “53BBF409“ + “39D54123“ 16);
private static BigInteger p = new BigInteger(
“FFFFFFFE“ + “FFFFFFFF“ + “FFFFFFFF“ + “FFFFFFFF“ + “FFFFFFFF“ + “00000000“ + “FFFFFFFF“ + “FFFFFFFF“ 16);
private static BigInteger a = new BigInteger(
“FFFFFFFE“ + “FFFFFFFF“ + “FFFFFFFF“ + “FFFFFFFF“ + “FFFFFFFF“ + “00000000“ + “FFFFFFFF“ + “FFFFFFFC“ 16);
private static BigInteger b = new BigInteger(
“28E9FA9E“ + “9D9F5E34“ + “4D5A9E4B“ + “CF6509A7“ + “F39789F5“ + “15AB8F92“ + “DDBCBD41“ + “4D940E93“ 16);
private static BigInteger gx = new BigInteger(
“32C4AE2C“ + “1F198119“ + “5F990446“ + “6A39C994“ + “8FE30BBF“ + “F2660BE1“ + “715A4589“ + “334C74C7“ 16);
private static BigInteger gy = new BigInteger(
“BC3736A2“ + “F4F6779C“ + “59BDCEE3“ + “6B692153“ + “D0A9877C“ + “C62A4740“ + “02DF32E5“ + “2139F0A0“ 16);
private static ECDomainParameters ecc_bc_spec;
private static int w = (int) Math.ceil(n.bitLength() * 1.0 / 2) - 1;
private static BigInteger _2w = new BigInteger(“2“).pow(w);
private static final int DIGEST_LENGTH = 32;
private static SecureRandom random = new SecureRandom();
private static ECCurve.Fp curve;
private static ECPoint G;
private boolean debug = false;
public boolean isDebug() {
return debug;
}
public void setDebug(boolean debug) {
this.debug = debug;
}
/**
* 以16进制打印字节数组
*
* @param b
*/
public static void printHexString(byte[] b) {
for (int i = 0; i < b.length; i++) {
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1) {
hex = ‘0‘ + hex;
}
System.out.print(hex.toUpperCase());
}
System.out.println();
}
/**
* 随机数生成器
*
* @param max
* @return
*/
private static BigInteger random(BigInteger max) {
BigInteger r = new BigInteger(256 random);
// int count = 1;
while (r.compareTo(max) >= 0) {
r = new BigInteger(128 random);
// count++;
}
// System.out.println(“count: “ + count);
return r;
}
/**
* 判断字节数组是否全0
*
* @param buffer
* @return
*/
private boolean allZero(byte[] buffer) {
for (int i = 0; i < buffer.length; i++) {
if (buffer[i] != 0)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 535 2019-01-07 16:24 SM2KeyPair.java
文件 7531 2019-01-07 17:09 SM3.java
文件 24405 2019-01-07 16:24 SM2.java
----------- --------- ---------- ----- ----
32471 3
相关资源
- java国密算法SM4加密.zip
- 大宝CA版本的国密算法DoubleCA-JCE实现,
- 国密版本的SSL库
- SM2 SM3 SM4国密算法JAVA与JS实现版本
- 国密SM2、SM3、SM4源代码
- sm2-sm4国密算法工具包及工具类245790
- SM2&SM3;&SM4;国密算法Java实现含详细测试
- SM2&SM3&SM4国密算法Java实现含详细测试
- [SM2_SM3_SM4]国密加解密算法java实现源码
- SM2&SM3&SM4国密算法Java实现含详细测试
- java实现国密算法SM2SM3SM4算法
- SM4国密加密解密JAVA代码实现.zip
- java调用Gmssl国密接口
- 国密SM3算法实现源代码只适合JAVA
- DoubleCA版本的国密算法JCE(Java Crypto
- JAVA国密算法pnc,sm2,sm3,sm4,jar包直
- 国密算法SM4加解密算法JAVA
- 真正国密SM2SM3SM4的前后台配套js和ja
- java实现国密SM3算法
- SMS4国密封装接口直接可用java.zip
- js+java实现国密算法SM2
- 国密算法SM3_SM4.zip
- 基于国密SM2加解密(JAVA版)
- 国密算法sm4的java实现
- SM 国密算法Java+JS
- sm4国密算法 java实现
- SM2&SM3&SM4国密规范及Java软算法实现
- java 国密算法实现包含SM2 SM3 SM4和数字
- 基于Java的SM2_SM3_SM4国密算法java源代码
- SM2_SM3_SM4国密算法java源码+PC工具
评论
共有 条评论