• 大小: 1.15M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-15
  • 语言: 其他
  • 标签: 其他  

资源简介

jce-doubleca-sample.2019.10.15.zip

资源截图

代码片段和文件信息

/**
 * 
 */
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_SM4_KEY_ALGORITHM = “SM4“;
// private static final String CIPHER_SM4_ALGORITHM = “SM4/ECB/PKCS5Padding“;
private static final String CIPHER_SM4_ALGORITHM = “SM4/CBC/PKCS5Padding“;
// private static final String CIPHER_SM4_ALGORITHM = “SM4/ECB/NOPadding“;
// private static final String CIPHER_SM4_ALGORITHM = “SM4/CBC/NOPadding“;
private static final String CIPHER_SM2_ALGORITHM = “SM2/NONE/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(““);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-05 20:12  jce-doubleca-sample\
     文件         376  2019-10-15 17:05  jce-doubleca-sample\.classpath
     文件         395  2018-03-05 11:28  jce-doubleca-sample\.project
     目录           0  2019-09-12 10:52  jce-doubleca-sample\.settings\
     文件         598  2018-03-05 11:28  jce-doubleca-sample\.settings\org.eclipse.jdt.core.prefs
     文件          81  2019-09-12 10:52  jce-doubleca-sample\.settings\org.hibernate.eclipse.console.prefs
     目录           0  2019-10-15 17:07  jce-doubleca-sample\bin\
     目录           0  2019-10-15 17:05  jce-doubleca-sample\lib\
     文件     1306164  2019-10-15 17:05  jce-doubleca-sample\lib\doubleca-jce-1.1.1-SNAPSHOT.jar
     目录           0  2018-03-06 23:24  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-06 23:24  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\
     文件       13049  2019-10-15 17:07  jce-doubleca-sample\src\com\doubleca\sample\pki\jce\Test.java

评论

共有 条评论