资源简介

提供获取加密证书接口、数字信封加密以及数字信封解密接口源码,IDEA编译,测试数据符合标准openssl,测试的时候要注意证书和私钥的存放路径

资源截图

代码片段和文件信息

/*  shaw 2018-12-17
* 数字信封加解密
*   证书(1代表加密证书,2代表起签名证书)
*  个人主页:https://user.qzone.qq.com/1939484341/infocenter
*/
package psic;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import server.ClientConf;
import server.GetEncPvk;
import server.JPkcs7;
import server.Util;
import sun.misc.base64Encoder;

import javax.crypto.Cipher;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.Security;;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;

public class SHAWApp {

    private CertificateFactory cf = null;
    private static final Map algMap = new HashMap();

    public SHAWApp() {
        try {
            Security.addProvider(new BouncyCastleProvider());
            this.cf = CertificateFactory.getInstance(“X.509“ “BC“);
            algMap.put(32772 “sha1withrsa“);
            algMap.put(32780 “sha256withrsa“);
            algMap.put(32771 “md5withrsa“);
            System.out.println(“SHAWApp初始化成功“);
        } catch (Exception var) {
            System.out.println(“SHAWApp初始化异常:“ + var.getMessage());
        }

    }

    //获取证书
    public String ShawGetCert(String keyLabel int certType) {
        String result = ““;
        object[] objs = new object[]{certType};
        if (!Util.paramCheck(objs)) {
            System.out.println(“必要的入参不能为空或null“);
            return result;
        } else {
            String certPath = ““;
            String certTypePath = ““;
            try {
                ClientConf conf = new ClientConf();
                String configPath = conf.CONFIG_PATH;
                if (keyLabel == null || ““.equals(keyLabel)) {
                    keyLabel = conf.getParamValue(“KeyLabel“);
                }
                certPath = configPath.substring(0 configPath.indexOf(“Client.conf“)) + keyLabel + System.getProperty(“file.separator“);
            } catch (Exception var) {
                System.out.println(“读取配置文件失败:“ + var.getMessage());
                return result;
            }
            try {
                String certTypeString = ““;
                if (certType == 1) {
                    certTypeString = “-CertEx.cer“;
                } else {
                    if (certType != 2) {
                        throw new Exception(“参数有误“);
                    }
                    certTypeString = “-CertSig.cer“;
                }
                certTypePath = certPath + keyLabel + certTypeString;
                FileInputStream fileInputStream = new FileInputStream(certTypePath);
                byte[] b = new byte[fileInputStream.available()];
                fileInputStream.read(b);
                fileInputStream.close();
                result = (new base64Encoder()).encode(b);
            } catch (Exception var) {
                System.out.println(“获取证书失败:“ + var.getMessage());
            }
            return result;
        }
    }

  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-12-18 15:04  SealEnvelope-OpenEnvelope-demo\
     目录           0  2018-12-18 15:04  SealEnvelope-OpenEnvelope-demo\.idea\
     文件         449  2018-12-18 13:51  SealEnvelope-OpenEnvelope-demo\.idea\compiler.xml
     目录           0  2018-12-18 15:04  SealEnvelope-OpenEnvelope-demo\.idea\copyright\
     文件          74  2018-12-18 13:51  SealEnvelope-OpenEnvelope-demo\.idea\copyright\profiles_settings.xml
     文件         340  2018-12-18 13:51  SealEnvelope-OpenEnvelope-demo\.idea\deployment.xml
     文件         496  2018-12-18 14:58  SealEnvelope-OpenEnvelope-demo\.idea\encodings.xml
     目录           0  2018-12-18 15:04  SealEnvelope-OpenEnvelope-demo\.idea\inspectionProfiles\
     文件         173  2018-12-18 13:51  SealEnvelope-OpenEnvelope-demo\.idea\inspectionProfiles\Project_Default.xml
     目录           0  2018-12-18 15:04  SealEnvelope-OpenEnvelope-demo\.idea\libraries\
     文件         316  2018-12-18 15:01  SealEnvelope-OpenEnvelope-demo\.idea\libraries\bcprov_jdk15on_1_59.xml
     文件         273  2018-12-18 13:51  SealEnvelope-OpenEnvelope-demo\.idea\misc.xml
     文件         248  2018-12-18 13:51  SealEnvelope-OpenEnvelope-demo\.idea\modules.xml
     文件       35119  2018-12-18 15:03  SealEnvelope-OpenEnvelope-demo\.idea\workspace.xml
     目录           0  2018-12-18 15:04  SealEnvelope-OpenEnvelope-demo\out\
     目录           0  2018-12-18 15:04  SealEnvelope-OpenEnvelope-demo\out\production\
     目录           0  2018-12-18 15:04  SealEnvelope-OpenEnvelope-demo\out\production\test\
     目录           0  2018-12-18 15:04  SealEnvelope-OpenEnvelope-demo\out\production\test\lib\
     文件      792825  2018-12-18 15:02  SealEnvelope-OpenEnvelope-demo\out\production\test\lib\bcpkix-jdk15on-1.59.jar
     文件     4092400  2018-12-18 14:40  SealEnvelope-OpenEnvelope-demo\out\production\test\lib\bcprov-jdk15on-1.59.jar
     目录           0  2018-12-18 15:04  SealEnvelope-OpenEnvelope-demo\out\production\test\psic\
     文件        6613  2018-12-18 15:03  SealEnvelope-OpenEnvelope-demo\out\production\test\psic\SHAWApp.class
     目录           0  2018-12-18 15:04  SealEnvelope-OpenEnvelope-demo\out\production\test\server\
     文件        1669  2018-12-18 15:03  SealEnvelope-OpenEnvelope-demo\out\production\test\server\base64.class
     文件        2115  2018-12-18 15:03  SealEnvelope-OpenEnvelope-demo\out\production\test\server\ClientConf.class
     文件        6073  2018-12-18 15:03  SealEnvelope-OpenEnvelope-demo\out\production\test\server\Envelope.class
     文件        2375  2018-12-18 15:03  SealEnvelope-OpenEnvelope-demo\out\production\test\server\GetEncPvk.class
     文件        9897  2018-12-18 15:03  SealEnvelope-OpenEnvelope-demo\out\production\test\server\JPkcs7.class
     文件        1677  2018-12-18 15:03  SealEnvelope-OpenEnvelope-demo\out\production\test\server\Random.class
     文件        6930  2018-12-18 15:03  SealEnvelope-OpenEnvelope-demo\out\production\test\server\Rsa.class
     文件        1959  2018-12-18 15:03  SealEnvelope-OpenEnvelope-demo\out\production\test\server\ThrDES.class
............此处省略18个文件信息

评论

共有 条评论