资源简介
提到PKCS,首先想到的是RSA的证书格式(类似,PKCS8,P12等),最近在和一家俄罗斯支付对接时,对方说加密成PKCS#7格式,当时就懵了,以为对方说错了,在这块卡了好几天,通过查资料,终于找到方法了。确实是PKCS#7加密,看来还是自己懂得太少。现在把方法分享出来,希望对遇到类似问题的朋友有所帮助
代码片段和文件信息
/*
* Copyright (c) 2017 All Rights Reserved
*/
/*
* 修订记录:
* 2017/8/24 09:34 创建
*
*/
package com.fmbank.gw.octopus.util.cryptography.svssign;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.misc.base64Decoder;
import sun.misc.base64Encoder;
import sun.security.pkcs.PKCS7;
/**
* 签名验签基础类
*
* @filename Svsbase.java
*
* @version 1.0
*
* @author ruofei
*
* @since 2017/8/24
*/
public class Svsbase {
private static final Logger logger = LoggerFactory.getLogger(Svsbase.class);
/**
* 签名算法,默认RSA,可通过setCryptAlg()方法设置
*/
private String cryptAlg = “RSA“;
/**
* 摘要算法,默认SHA1,可通过setDigestAlg()方法设置
*/
private String digestAlg = “SHA1“;
protected X509Certificate signCert;
protected X509CertChecker certChecker;
public Svsbase() {
}
/**
* 初始化证书
* @param fileName 证书路径
* @throws Exception
*/
public void initSignCertFile(String fileName) throws Exception {
this.signCert = null;
FileInputStream fin = null;
BufferedInputStream bin = null;
try{
fin= new FileInputStream(fileName);
bin = new BufferedInputStream(fin);
CertificateFactory cf = CertificateFactory.getInstance(“X.509“);
if(bin.available() > 0) {
this.signCert = (X509Certificate)cf.generateCertificate(bin);
}
}finally{
try{
if(bin!=null){
bin.close();
}
}catch(Exception ex){
logger.info(““ex);
}
try{
if(fin!=null){
fin.close();
}
}catch(Exception ex){
logger.info(““ex);
}
}
}
public void initSignCert(String szB64Cert) throws Exception {
ByteArrayInputStream bin = new ByteArrayInputStream(base64Decode(szB64Cert));
CertificateFactory cf = CertificateFactory.getInstance(“X.509“);
if(bin.available() > 0) {
this.signCert = (X509Certificate)cf.generateCertificate(bin);
}
}
public void initSignCert(X509Certificate cert) {
this.signCert = cert;
}
public X509Certificate getSignCert() {
return this.signCert;
}
public String getEncodedSignCert() throws Exception {
return base64Encode(this.signCert.getEncoded());
}
public void setCertChecker(X509CertChecker checker) {
this.certChecker = checker;
}
public X509CertChecker getCertChecker() {
return this.certChecker;
}
public int checkSignCert() {
return X509CertChecker.checkCertValidity(this.signCert);
}
public int checkSignCert(X509Certificate issuerCert) {
if(issuerCert == null) {
return -1;
} else {
int nret = X509CertChecker.checkCertValidity(this.signCert);
return nret != 0?nret: X509CertCheck
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10752 2018-12-26 15:32 RSA的PKCS#7加解密验签\OpenSSL生成加密证书.doc
文件 5800 2018-07-20 15:55 RSA的PKCS#7加解密验签\Svsba
文件 6382 2018-07-20 15:55 RSA的PKCS#7加解密验签\SvsSign.java
文件 626 2018-09-13 16:50 RSA的PKCS#7加解密验签\SvsSignExample.java
文件 9647 2018-07-20 15:55 RSA的PKCS#7加解密验签\SvsVerify.java
文件 5640 2018-07-20 15:55 RSA的PKCS#7加解密验签\X509CertChecker.java
文件 140 2018-12-26 15:32 RSA的PKCS#7加解密验签\read me.txt
目录 0 2018-12-26 15:32 RSA的PKCS#7加解密验签\
相关资源
- IBM Rational Software Architect 9.0破解文件
- Universal Extractor(万能文件解包工具)
- DXperienceUniversal-11.1.7.part06
- DXperienceUniversal-11.1.7.part08
- DXperienceUniversal-11.1.7.part14
- DXperienceUniversal-11.1.7.part15
- DXperienceUniversal-11.1.7.part10
- DXperienceUniversal-11.1.7.part13
- DXperienceUniversal-11.1.7.part03
- DXperienceUniversal-11.1.7.part02
- DXperienceUniversal-11.1.7.part09
- DXperienceUniversal-11.1.7.part19
- DXperienceUniversal-11.1.7.part12
- DXperienceUniversal-11.1.7.part18
- DXperienceUniversal-11.1.7.part16
- DXperienceUniversal-11.1.7.part20
- DXperienceUniversal-11.1.7.part07
- DXperienceUniversal-11.1.7.part17
- DXperienceUniversal-11.1.7.part04
- IBM 2U Universal Tape Autoloader产品手册
- IBM 4U Universal Tape Library产品手册
- 密码学实验RSA加解密
- yafu暴力分解
- 毕业设计-RSA算法(源代码+论文+ppt
- delphi下用Lockbox中rsa进行加解密的范例
- linux c 使用openssl实现SHA1WithRSA实现,签
- Learning Generative Adversarial Networks 无水印
- 论文研究 - 气象对印度两个大城市的
- Learning Generative Adversarial Networks
- Universalimageloader
评论
共有 条评论