本文整理汇总了Java中org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute类的典型用法代码示例。如果您正苦于以下问题:Java SMIMECapabilitiesAttribute类的具体用法?Java SMIMECapabilitiesAttribute怎么用?Java SMIMECapabilitiesAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SMIMECapabilitiesAttribute类属于org.bouncycastle.asn1.smime包,在下文中一共展示了SMIMECapabilitiesAttribute类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: signMessage
import org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute; //导入依赖的package包/类
private static MimeMultipart signMessage(MimeBodyPart mbp)
throws Exception
{
// Open the key store
char[] pwd = "password".toCharArray();
KeyStore ks = MailsterKeyStoreFactory.loadKeyStore("PKCS12", "clients.p12", pwd);
String alias = MailsterKeyStoreFactory.DEFAULT_CERT_ALIAS;
Certificate[] chain = ks.getCertificateChain(alias);
PrivateKey privateKey = (PrivateKey) ks.getKey(alias, pwd);
ArrayList<Certificate> certList = new ArrayList<Certificate>();
for (int i = 0; i < chain.length; i++)
certList.add(chain[i]);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
SMIMECapabilityVector caps = new SMIMECapabilityVector();
caps.addCapability(SMIMECapability.dES_EDE3_CBC);
caps.addCapability(SMIMECapability.rC2_CBC, 128);
caps.addCapability(SMIMECapability.dES_CBC);
caps.addCapability(SMIMECapability.aES256_CBC);
signedAttrs.add(new SMIMECapabilitiesAttribute(caps));
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(privateKey, (X509Certificate) chain[0],
SMIMESignedGenerator.DIGEST_SHA1,
new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
return gen.generate(mbp, "BC");
}
开发者ID:edeoliveira,项目名称:Mailster,代码行数:40,代码来源:SendMultipleMail.java
示例2: signMessage
import org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute; //导入依赖的package包/类
private static MimeMultipart signMessage(MimeBodyPart mbp)
throws Exception
{
// Open the key store
char[] pwd = "password".toCharArray();
KeyStore ks = MailsterKeyStoreFactory.loadKeyStore("PKCS12", "clients.p12", pwd);
String alias = MailsterKeyStoreFactory.DEFAULT_CERT_ALIAS;
Certificate[] chain = ks.getCertificateChain(alias);
PrivateKey privateKey = (PrivateKey) ks.getKey(alias, pwd);
ArrayList<Certificate> certList = new ArrayList<Certificate>();
for (int i = 0; i < chain.length; i++)
certList.add(chain[i]);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
SMIMECapabilityVector caps = new SMIMECapabilityVector();
caps.addCapability(SMIMECapability.dES_EDE3_CBC);
caps.addCapability(SMIMECapability.rC2_CBC, 128);
caps.addCapability(SMIMECapability.dES_CBC);
caps.addCapability(SMIMECapability.aES256_CBC);
signedAttrs.add(new SMIMECapabilitiesAttribute(caps));
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(privateKey, (X509Certificate) chain[0],
SMIMESignedGenerator.DIGEST_SHA1,
new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
return gen.generate(mbp, "BC");
}
开发者ID:edeoliveira,项目名称:Mailster,代码行数:40,代码来源:EncryptedMailTest.java
示例3: generateSignedAttributes
import org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute; //导入依赖的package包/类
private ASN1EncodableVector generateSignedAttributes()
{
ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
SMIMECapabilityVector caps = new SMIMECapabilityVector();
caps.addCapability(SMIMECapability.dES_EDE3_CBC);
caps.addCapability(SMIMECapability.rC2_CBC, 128);
caps.addCapability(SMIMECapability.dES_CBC);
signedAttrs.add(new SMIMECapabilitiesAttribute(caps));
return signedAttrs;
}
开发者ID:credentials,项目名称:irma_future_id,代码行数:14,代码来源:NewSMIMESignedTest.java
示例4: sign
import org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute; //导入依赖的package包/类
@PublicAtsApi
public Package sign( Package sourcePackage ) throws ActionException {
try {
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
Security.addProvider(new BouncyCastleProvider());
}
KeyStore ks = getKeystore();
PrivateKey privateKey = (PrivateKey) ks.getKey(aliasOrCN, certPassword.toCharArray());
X509Certificate cer = (X509Certificate) ks.getCertificate(aliasOrCN);
/* Create the SMIMESignedGenerator */
SMIMECapabilityVector capabilities = new SMIMECapabilityVector();
capabilities.addCapability(SMIMECapability.dES_EDE3_CBC);
capabilities.addCapability(SMIMECapability.rC2_CBC, 128);
capabilities.addCapability(SMIMECapability.dES_CBC);
ASN1EncodableVector attributes = new ASN1EncodableVector();
attributes.add(new SMIMEEncryptionKeyPreferenceAttribute(new IssuerAndSerialNumber(new X500Name( (cer).getIssuerDN()
.getName()),
cer.getSerialNumber())));
attributes.add(new SMIMECapabilitiesAttribute(capabilities));
if (signatureAlgorithm == null) {
signatureAlgorithm = SignatureAlgorithm.DSA.equals(privateKey.getAlgorithm())
? "SHA1withDSA"
: "MD5withRSA";
}
SMIMESignedGenerator signer = new SMIMESignedGenerator();
JcaSimpleSignerInfoGeneratorBuilder signerGeneratorBuilder = new JcaSimpleSignerInfoGeneratorBuilder();
signerGeneratorBuilder.setProvider(BouncyCastleProvider.PROVIDER_NAME);
signerGeneratorBuilder.setSignedAttributeGenerator(new AttributeTable(attributes));
signer.addSignerInfoGenerator(signerGeneratorBuilder.build(signatureAlgorithm, privateKey,
cer));
/* Add the list of certs to the generator */
List<X509Certificate> certList = new ArrayList<X509Certificate>();
certList.add(cer);
Store<?> certs = new JcaCertStore(certList);
signer.addCertificates(certs);
/* Sign the message */
Session session = Session.getDefaultInstance(System.getProperties(), null);
MimeMultipart mm = signer.generate(getMimeMessage(sourcePackage));
MimeMessage signedMessage = new MimeMessage(session);
/* Set all original MIME headers in the signed message */
Enumeration<?> headers = getMimeMessage(sourcePackage).getAllHeaderLines();
while (headers.hasMoreElements()) {
signedMessage.addHeaderLine((String) headers.nextElement());
}
/* Set the content of the signed message */
signedMessage.setContent(mm);
signedMessage.saveChanges();
return new MimePackage(signedMessage);
} catch (Exception e) {
throw new ActionException(EXCEPTION_WHILE_SIGNING, e);
}
}
开发者ID:Axway,项目名称:ats-framework,代码行数:65,代码来源:SMimePackageEncryptor.java
示例5: signMessage
import org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute; //导入依赖的package包/类
private MimeBodyPart signMessage(MimeBodyPart bodyPart) throws Exception{
X509Certificate cert = partnershipDVO.getVerifyX509Certificate();
/* Create the SMIMESignedGenerator */
SMIMECapabilityVector capabilities = new SMIMECapabilityVector();
capabilities.addCapability(SMIMECapability.dES_EDE3_CBC);
capabilities.addCapability(SMIMECapability.rC2_CBC, 128);
capabilities.addCapability(SMIMECapability.dES_CBC);
ASN1EncodableVector attributes = new ASN1EncodableVector();
attributes.add(new SMIMEEncryptionKeyPreferenceAttribute(
new IssuerAndSerialNumber(new X509Name(cert.getIssuerDN().getName()), cert.getSerialNumber()))
);
attributes.add(new SMIMECapabilitiesAttribute(capabilities));
SMIMESignedGenerator signer = new SMIMESignedGenerator();
signer.setContentTransferEncoding("base64");
signer.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(SECURITY_PROVIDER)
.setSignedAttributeGenerator(new AttributeTable(attributes))
.build("SHA1withRSA",
keyMan.getPrivateKey(),
partnershipDVO.getVerifyX509Certificate()));
// Add the list of certs to the generator
ArrayList certList = new ArrayList();
certList.add(cert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
signer.addCertificates(new JcaCertStore(certList));
// Sign body part
MimeMultipart mm = signer.generate(bodyPart);
InternetHeaders headers = new InternetHeaders();
boolean isContentTypeFolded = new Boolean(System.getProperty("mail.mime.foldtext","true")).booleanValue();
headers.setHeader("Content-Type", isContentTypeFolded? mm.getContentType():mm.getContentType().replaceAll("\\s", " "));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mm.writeTo(baos);
MimeBodyPart signedPart = new MimeBodyPart(headers, baos.toByteArray());
return signedPart;
}
开发者ID:cecid,项目名称:hermes,代码行数:43,代码来源:IncomingMessageProcessorTest.java
示例6: perform
import org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute; //导入依赖的package包/类
public TestResult perform()
{
SMIMECapabilityVector caps = new SMIMECapabilityVector();
caps.addCapability(SMIMECapability.dES_EDE3_CBC);
caps.addCapability(SMIMECapability.rC2_CBC, 128);
caps.addCapability(SMIMECapability.dES_CBC);
SMIMECapabilitiesAttribute attr = new SMIMECapabilitiesAttribute(caps);
SMIMEEncryptionKeyPreferenceAttribute pref = new SMIMEEncryptionKeyPreferenceAttribute(
new RecipientKeyIdentifier(new DEROctetString(new byte[8]), new DERGeneralizedTime("20070315173729Z"), null));
try
{
if (!isSameAs(attr.getEncoded(), attrBytes))
{
return new SimpleTestResult(false, getName() + ": Failed attr data check");
}
ByteArrayInputStream bIn = new ByteArrayInputStream(attrBytes);
ASN1InputStream aIn = new ASN1InputStream(bIn);
ASN1Primitive o = aIn.readObject();
if (!attr.equals(o))
{
return new SimpleTestResult(false, getName() + ": Failed equality test for attr");
}
if (!isSameAs(pref.getEncoded(), prefBytes))
{
return new SimpleTestResult(false, getName() + ": Failed attr data check");
}
bIn = new ByteArrayInputStream(prefBytes);
aIn = new ASN1InputStream(bIn);
o = aIn.readObject();
if (!pref.equals(o))
{
return new SimpleTestResult(false, getName() + ": Failed equality test for pref");
}
return new SimpleTestResult(true, getName() + ": Okay");
}
catch (Exception e)
{
return new SimpleTestResult(false, getName() + ": Failed - exception " + e.toString(), e);
}
}
开发者ID:credentials,项目名称:irma_future_id,代码行数:51,代码来源:SMIMETest.java
示例7: testCompressedSHA1WithRSA
import org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute; //导入依赖的package包/类
public void testCompressedSHA1WithRSA()
throws Exception
{
List certList = new ArrayList();
certList.add(origCert);
certList.add(signCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
SMIMECapabilityVector caps = new SMIMECapabilityVector();
caps.addCapability(SMIMECapability.dES_EDE3_CBC);
caps.addCapability(SMIMECapability.rC2_CBC, 128);
caps.addCapability(SMIMECapability.dES_CBC);
signedAttrs.add(new SMIMECapabilitiesAttribute(caps));
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(origKP.getPrivate(), origCert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
gen.addCertificatesAndCRLs(certs);
MimeMultipart smp = gen.generate(msg, "BC");
MimeMessage bp2 = new MimeMessage((Session)null);
bp2.setContent(smp);
bp2.saveChanges();
SMIMECompressedGenerator cgen = new SMIMECompressedGenerator();
MimeBodyPart cbp = cgen.generate(bp2, SMIMECompressedGenerator.ZLIB);
SMIMECompressed cm = new SMIMECompressed(cbp);
MimeMultipart mm = (MimeMultipart)SMIMEUtil.toMimeBodyPart(cm.getContent()).getContent();
SMIMESigned s = new SMIMESigned(mm);
ByteArrayOutputStream _baos = new ByteArrayOutputStream();
msg.writeTo(_baos);
_baos.close();
byte[] _msgBytes = _baos.toByteArray();
_baos = new ByteArrayOutputStream();
s.getContent().writeTo(_baos);
_baos.close();
byte[] _resBytes = _baos.toByteArray();
assertEquals(true, Arrays.areEqual(_msgBytes, _resBytes));
certs = s.getCertificatesAndCRLs("Collection", "BC");
SignerInformationStore signers = s.getSignerInfos();
Collection c = signers.getSigners();
Iterator it = c.iterator();
while (it.hasNext())
{
SignerInformation signer = (SignerInformation)it.next();
Collection certCollection = certs.getCertificates(selectorConverter.getCertSelector(signer.getSID()));
Iterator certIt = certCollection.iterator();
X509Certificate cert = (X509Certificate)certIt.next();
assertEquals(true, signer.verify(cert, "BC"));
}
}
开发者ID:credentials,项目名称:irma_future_id,代码行数:73,代码来源:SMIMECompressedTest.java
注:本文中的org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论