本文整理汇总了Java中org.bouncycastle.cms.CMSProcessable类的典型用法代码示例。如果您正苦于以下问题:Java CMSProcessable类的具体用法?Java CMSProcessable怎么用?Java CMSProcessable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CMSProcessable类属于org.bouncycastle.cms包,在下文中一共展示了CMSProcessable类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preSign
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
public DigestInfo preSign(List<DigestInfo> digestInfos, List<X509Certificate> signingCertificateChain,
IdentityDTO identity, AddressDTO address, byte[] photo) throws NoSuchAlgorithmException {
CMSSignedDataGenerator generator = createCMSSignedDataGenerator(signingCertificateChain);
byte[] toBeSigned = getToBeSigned();
CMSProcessable content = new CMSProcessableByteArray(toBeSigned);
CMSProvider provider = new CMSProvider();
SHA1WithRSAProxySignature.reset();
try {
generator.generate(content, true, provider);
} catch (CMSException e) {
throw new RuntimeException(e);
}
byte[] digestValue = SHA1WithRSAProxySignature.getDigestValue();
String description = getSignatureDescription();
DigestInfo digestInfo = new DigestInfo(digestValue, "SHA1", description);
return digestInfo;
}
示例2: SMIMESigned
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
/**
* base constructor for a signed message with encapsulated content.
*
* @exception MessagingException on an error extracting the signature or
* otherwise processing the message.
* @exception SMIMEException if the body part encapsulated in the message cannot be extracted.
* @exception CMSException if some other problem occurs.
*/
public SMIMESigned(
Part message)
throws MessagingException, CMSException, SMIMEException
{
super(getInputStream(message));
this.message = message;
CMSProcessable cont = this.getSignedContent();
if (cont != null)
{
byte[] contBytes = (byte[])cont.getContent();
this.content = SMIMEUtil.toMimeBodyPart(contBytes);
}
}
示例3: assinar
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
public byte[] assinar(KeyStore keystore, String alias, char[] password, byte[] request) {
try {
PrivateKey key = (PrivateKey) keystore.getKey(alias, password);
X509Certificate cert = (X509Certificate) keystore.getCertificate(alias);
List<X509Certificate> certs = new ArrayList<X509Certificate>();
certs.add(cert);
CertStore certsAndCrls = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certs));
// setup the generator
CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
generator.addSigner(key, cert, CMSSignedDataGenerator.DIGEST_SHA256);
generator.addCertificatesAndCRLs(certsAndCrls);
// Create the signed data object
CMSProcessable data = new CMSProcessableByteArray(request);
CMSSignedData signed = generator.generate(data, true, keystore.getProvider());
return signed.getEncoded();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例4: testSHA1WithRSANoAttributes
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
public void testSHA1WithRSANoAttributes()
throws Exception
{
List certList = new ArrayList();
CMSProcessable msg = new CMSProcessableByteArray("Hello world!".getBytes());
certList.add(_origCert);
certList.add(_signCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), BC);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);
gen.addCertificatesAndCRLs(certs);
CMSSignedData s = gen.generate(CMSSignedDataGenerator.DATA, msg, false, BC, false);
//
// compute expected content digest
//
MessageDigest md = MessageDigest.getInstance("SHA1", BC);
verifySignatures(s, md.digest("Hello world!".getBytes()));
}
示例5: rsaPSSTest
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
private void rsaPSSTest(String digestName, String digestOID)
throws Exception
{
List certList = new ArrayList();
CMSProcessable msg = new CMSProcessableByteArray("Hello world!".getBytes());
certList.add(_origCert);
certList.add(_signCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), BC);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.ENCRYPTION_RSA_PSS, digestOID);
gen.addCertificatesAndCRLs(certs);
CMSSignedData s = gen.generate(CMSSignedDataGenerator.DATA, msg, false, BC, false);
//
// compute expected content digest
//
MessageDigest md = MessageDigest.getInstance(digestName, BC);
verifySignatures(s, md.digest("Hello world!".getBytes()));
}
示例6: testCertStoreReplacement
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
public void testCertStoreReplacement()
throws Exception
{
List certList = new ArrayList();
CMSProcessable msg = new CMSProcessableByteArray("Hello World!".getBytes());
certList.add(_signDsaCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), BC);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);
gen.addCertificatesAndCRLs(certs);
CMSSignedData sd = gen.generate(msg, BC);
//
// create new certstore
//
certList = new ArrayList();
certList.add(_origCert);
certList.add(_signCert);
certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), BC);
//
// replace certs
//
sd = CMSSignedData.replaceCertificatesAndCRLs(sd, certs);
verifySignatures(sd);
}
示例7: testEncapsulatedCertStoreReplacement
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
public void testEncapsulatedCertStoreReplacement()
throws Exception
{
List certList = new ArrayList();
CMSProcessable msg = new CMSProcessableByteArray("Hello World!".getBytes());
certList.add(_signDsaCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), BC);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);
gen.addCertificatesAndCRLs(certs);
CMSSignedData sd = gen.generate(msg, true, BC);
//
// create new certstore
//
certList = new ArrayList();
certList.add(_origCert);
certList.add(_signCert);
certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), BC);
//
// replace certs
//
sd = CMSSignedData.replaceCertificatesAndCRLs(sd, certs);
verifySignatures(sd);
}
示例8: testCertOrdering1
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
public void testCertOrdering1()
throws Exception
{
List certList = new ArrayList();
CMSProcessable msg = new CMSProcessableByteArray("Hello World!".getBytes());
certList.add(_origCert);
certList.add(_signCert);
certList.add(_signDsaCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), BC);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);
gen.addCertificatesAndCRLs(certs);
CMSSignedData sd = gen.generate(msg, true, BC);
certs = sd.getCertificatesAndCRLs("Collection", BC);
Iterator it = certs.getCertificates(null).iterator();
assertEquals(_origCert, it.next());
assertEquals(_signCert, it.next());
assertEquals(_signDsaCert, it.next());
}
示例9: testCertOrdering2
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
public void testCertOrdering2()
throws Exception
{
List certList = new ArrayList();
CMSProcessable msg = new CMSProcessableByteArray("Hello World!".getBytes());
certList.add(_signCert);
certList.add(_signDsaCert);
certList.add(_origCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), BC);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);
gen.addCertificatesAndCRLs(certs);
CMSSignedData sd = gen.generate(msg, true, BC);
certs = sd.getCertificatesAndCRLs("Collection", BC);
Iterator it = certs.getCertificates(null).iterator();
assertEquals(_signCert, it.next());
assertEquals(_signDsaCert, it.next());
assertEquals(_origCert, it.next());
}
示例10: testSHA1WithRSANoAttributes
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
public void testSHA1WithRSANoAttributes()
throws Exception
{
List certList = new ArrayList();
CMSProcessable msg = new CMSProcessableByteArray(TEST_MESSAGE.getBytes());
certList.add(_origCert);
certList.add(_signCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), BC);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);
gen.addCertificatesAndCRLs(certs);
CMSSignedData s = gen.generate(CMSSignedDataGenerator.DATA, msg, false, BC, false);
CMSSignedDataParser sp = new CMSSignedDataParser(
new CMSTypedStream(new ByteArrayInputStream(TEST_MESSAGE.getBytes())), s.getEncoded());
sp.getSignedContent().drain();
//
// compute expected content digest
//
MessageDigest md = MessageDigest.getInstance("SHA1", BC);
verifySignatures(sp, md.digest(TEST_MESSAGE.getBytes()));
}
示例11: testDSANoAttributes
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
public void testDSANoAttributes()
throws Exception
{
List certList = new ArrayList();
CMSProcessable msg = new CMSProcessableByteArray(TEST_MESSAGE.getBytes());
certList.add(_origDsaCert);
certList.add(_signCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), BC);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addSigner(_origDsaKP.getPrivate(), _origDsaCert, CMSSignedDataGenerator.DIGEST_SHA1);
gen.addCertificatesAndCRLs(certs);
CMSSignedData s = gen.generate(CMSSignedDataGenerator.DATA, msg, false, BC, false);
CMSSignedDataParser sp = new CMSSignedDataParser(
new CMSTypedStream(new ByteArrayInputStream(TEST_MESSAGE.getBytes())), s.getEncoded());
sp.getSignedContent().drain();
//
// compute expected content digest
//
MessageDigest md = MessageDigest.getInstance("SHA1", BC);
verifySignatures(sp, md.digest(TEST_MESSAGE.getBytes()));
}
示例12: TimeStampToken
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
public TimeStampToken(CMSSignedData signedData)
throws TSPException, IOException
{
this.tsToken = signedData;
if (!this.tsToken.getSignedContentTypeOID().equals(PKCSObjectIdentifiers.id_ct_TSTInfo.getId()))
{
throw new TSPValidationException("ContentInfo object not for a time stamp.");
}
Collection signers = tsToken.getSignerInfos().getSigners();
if (signers.size() != 1)
{
throw new IllegalArgumentException("Time-stamp token signed by "
+ signers.size()
+ " signers, but it must contain just the TSA signature.");
}
tsaSignerInfo = (SignerInformation)signers.iterator().next();
try
{
CMSProcessable content = tsToken.getSignedContent();
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
content.write(bOut);
ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(bOut.toByteArray()));
this.tstInfo = new TimeStampTokenInfo(TSTInfo.getInstance(aIn.readObject()));
Attribute attr = tsaSignerInfo.getSignedAttributes().get(PKCSObjectIdentifiers.id_aa_signingCertificate);
if (attr != null)
{
SigningCertificate signCert = SigningCertificate.getInstance(attr.getAttrValues().getObjectAt(0));
this.certID = new CertID(ESSCertID.getInstance(signCert.getCerts()[0]));
}
else
{
attr = tsaSignerInfo.getSignedAttributes().get(PKCSObjectIdentifiers.id_aa_signingCertificateV2);
if (attr == null)
{
throw new TSPValidationException("no signing certificate attribute found, time stamp invalid.");
}
SigningCertificateV2 signCertV2 = SigningCertificateV2.getInstance(attr.getAttrValues().getObjectAt(0));
this.certID = new CertID(ESSCertIDv2.getInstance(signCertV2.getCerts()[0]));
}
}
catch (CMSException e)
{
throw new TSPException(e.getMessage(), e.getUnderlyingException());
}
}
示例13: setContent
import org.bouncycastle.cms.CMSProcessable; //导入依赖的package包/类
public void setContent(CMSProcessable content) {
this.content = content;
}