资源简介

大宝CA完整地实现了国密SM2、SM3、SM4算法和JKS功能,可加密、解密、数字签名、验证、摘要计算,可存储和应用SM2软证书和软密钥。可惜没有源码,只有详细的测试和应用样例代码。

资源截图

代码片段和文件信息

/**
 * 
 */
package com.doubleca.sample.pki.jce;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.KeyStore.Entry;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.SignatureException;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Enumeration;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import com.doubleca.b146.c16.util.encoders.base64;

import doubleca.security.provider.DoubleCA;
import doubleca.security.provider.jdk7.sm4.SM4KeySpec;

/**
 * @author
 *
 */
public class Test
{
private static final String SIGNATURE_KEY_ALGORITHM = “SM2“;
private static final String SIGNATURE_ALGORITHM = “SM3withSM2“;
private static final int SIGNATURE_KEY_SIZE = 256;
private static final String DIGEST_ALGORITHM = “SM3“;
private static final String CIPHER_KEY_ALGORITHM = “SM4“;
// private static final String CIPHER_ALGORITHM = “SM4/ECB/PKCS5Padding“;
private static final String CIPHER_ALGORITHM = “SM4/CBC/PKCS5Padding“;
// private static final String CIPHER_ALGORITHM = “SM4/ECB/NOPadding“;
// private static final String CIPHER_ALGORITHM = “SM4/CBC/NOPadding“;

/**
 * @param args
 */
public static void main(String[] args)
{
// TODO Auto-generated method stub
/**
 * 说明:JDK7版本及以上,JDK需要使用无限制的策略文件 UnlimitedJCEPolicy
 * 否则,SM2密钥长度为256位,JCE无法调用成功
 */
try
{
Security.addProvider(new DoubleCA());
System.out.println(““);
System.out.println(“TestSM2KeyPairGenerator“);
KeyPair key = TestSM2KeyPairGenerator();
System.out.println(““);
System.out.println(“TestSM2KeyFactory“);
TestSM2KeyFactory(key.getPublic().getEncoded() key.getPrivate().getEncoded());
System.out.println(““);
System.out.println(“TestSM3Digest“);
TestSM3Digest();
System.out.println(““);
System.out.println(“TestSM4Cipher“);
SecretKey sm4key = TestSM4Cipher();
System.out.println(““);
System.out.println(“TestSM2AsymmetricCipher“);
TestSM2AsymmetricCipher(key);
System.out.println(““);
System.out.println(“TestSM2Signature“);
TestSM2Signature(key);
System.out.println(““);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-05 20:12  jce-doubleca-sample\
     文件         376  2018-03-05 11:44  jce-doubleca-sample\.classpath
     文件         395  2018-03-05 11:28  jce-doubleca-sample\.project
     目录           0  2018-03-05 20:12  jce-doubleca-sample\.settings\
     文件         598  2018-03-05 11:28  jce-doubleca-sample\.settings\org.eclipse.jdt.core.prefs
     目录           0  2018-03-05 22:52  jce-doubleca-sample\bin\
     目录           0  2018-03-05 20:12  jce-doubleca-sample\lib\
     文件      918584  2018-03-05 11:31  jce-doubleca-sample\lib\doubleca-jce-0.9.2-SNAPSHOT.jar
     目录           0  2018-03-05 21:43  jce-doubleca-sample\resources\
     文件        3429  2018-03-05 21:29  jce-doubleca-sample\resources\1E7A9FA952485DBD8452B1B7BDBB8DF4.dcks
     文件         590  2018-03-05 21:33  jce-doubleca-sample\resources\sm2cert.cer
     文件        1377  2018-03-05 22:44  jce-doubleca-sample\resources\SM2SigningCert.dcks
     目录           0  2018-03-05 20:12  jce-doubleca-sample\src\
     目录           0  2018-03-05 20:12  jce-doubleca-sample\src\com\
     目录           0  2018-03-05 20:12  jce-doubleca-sample\src\com\doubleca\
     目录           0  2018-03-05 20:12  jce-doubleca-sample\src\com\doubleca\sample\
     目录           0  2018-03-05 20:12  jce-doubleca-sample\src\com\doubleca\sample\pki\
     目录           0  2018-03-05 20:12  jce-doubleca-sample\src\com\doubleca\sample\pki\jce\
     文件       12823  2018-03-05 22:48  jce-doubleca-sample\src\com\doubleca\sample\pki\jce\Test.java

评论

共有 条评论