本文整理汇总了Java中org.bouncycastle.operator.OutputEncryptor类的典型用法代码示例。如果您正苦于以下问题:Java OutputEncryptor类的具体用法?Java OutputEncryptor怎么用?Java OutputEncryptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OutputEncryptor类属于org.bouncycastle.operator包,在下文中一共展示了OutputEncryptor类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
public PKCS8EncryptedPrivateKeyInfo build(
OutputEncryptor encryptor)
{
try
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream cOut = encryptor.getOutputStream(bOut);
cOut.write(privateKeyInfo.getEncoded());
cOut.close();
return new PKCS8EncryptedPrivateKeyInfo(new EncryptedPrivateKeyInfo(encryptor.getAlgorithmIdentifier(), bOut.toByteArray()));
}
catch (IOException e)
{
throw new IllegalStateException("cannot encode privateKeyInfo");
}
}
示例2: addEncryptedData
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
private PKCS12PfxPduBuilder addEncryptedData(OutputEncryptor dataEncryptor, ASN1Sequence data)
throws IOException
{
CMSEncryptedDataGenerator envGen = new CMSEncryptedDataGenerator();
try
{
dataVector.add(envGen.generate(new CMSProcessableByteArray(data.getEncoded()), dataEncryptor).toASN1Structure());
}
catch (CMSException e)
{
throw new PKCSIOException(e.getMessage(), e.getCause());
}
return this;
}
示例3: doOpen
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
private OutputStream doOpen(
ASN1ObjectIdentifier dataType,
OutputStream out,
OutputEncryptor encryptor)
throws IOException, CMSException
{
ASN1EncodableVector recipientInfos = new ASN1EncodableVector();
GenericKey encKey = encryptor.getKey();
Iterator it = recipientInfoGenerators.iterator();
while (it.hasNext())
{
RecipientInfoGenerator recipient = (RecipientInfoGenerator)it.next();
recipientInfos.add(recipient.generate(encKey));
}
return open(dataType, out, recipientInfos, encryptor);
}
示例4: encryptKey
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
private static byte[] encryptKey(KeyPair key, String resource, PasswordCallback newPassword) throws IOException {
char[] passwordChars = newPassword.queryPassword(resource);
if (passwordChars == null) {
throw new PasswordRequiredException(resource);
}
byte[] encoded;
try {
PKCS8EncryptedPrivateKeyInfoBuilder encryptedPrivateKeyInfoBuilder = new PKCS8EncryptedPrivateKeyInfoBuilder(
KeyHelper.encodePrivateKey(key.getPrivate()));
OutputEncryptor encryptor = OUTPUT_ENCRYPTOR_BUILDER.build(passwordChars);
encoded = encryptedPrivateKeyInfoBuilder.build(encryptor).getEncoded();
} catch (OperatorCreationException e) {
throw new CertProviderException(e);
}
return encoded;
}
示例5: make
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
/**
* if we get here we expect the Mime body part to be well defined.
*/
private MimeBodyPart make(
MimeBodyPart content,
OutputEncryptor encryptor)
throws SMIMEException
{
try
{
MimeBodyPart data = new MimeBodyPart();
data.setContent(new ContentEncryptor(content, encryptor), ENCRYPTED_CONTENT_TYPE);
data.addHeader("Content-Type", ENCRYPTED_CONTENT_TYPE);
data.addHeader("Content-Disposition", "attachment; filename=\"smime.p7m\"");
data.addHeader("Content-Description", "S/MIME Encrypted Message");
data.addHeader("Content-Transfer-Encoding", encoding);
return data;
}
catch (MessagingException e)
{
throw new SMIMEException("exception putting multi-part together.", e);
}
}
示例6: generate
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
/**
* generate an enveloped object that contains an SMIME Enveloped
* object using the given provider from the contents of the passed in
* message
*/
public MimeBodyPart generate(
MimeMessage message,
OutputEncryptor encryptor)
throws SMIMEException
{
try
{
message.saveChanges(); // make sure we're up to date.
}
catch (MessagingException e)
{
throw new SMIMEException("unable to save message", e);
}
return make(makeContentBodyPart(message), encryptor);
}
示例7: testHeaders
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
@Test
public void testHeaders()
throws Exception {
InternetHeaders ih = new InternetHeaders();
ih.addHeader("Content-Type", "application/xml");
MimeBodyPart _msg = new MimeBodyPart(ih, "<customer name=\"bill\"/>".getBytes());
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
OutputEncryptor encryptor = new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC)
.setProvider("BC")
.build();
RecipientInfoGenerator generator = new JceKeyTransRecipientInfoGenerator(cert);
gen.addRecipientInfoGenerator(generator);
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(_msg, encryptor);
output(mp);
}
示例8: build
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
/**
* Build the PKIArchiveControl using the passed in encryptor to encrypt its contents.
*
* @param contentEncryptor a suitable content encryptor.
* @return a PKIArchiveControl object.
* @throws CMSException in the event the build fails.
*/
public PKIArchiveControl build(OutputEncryptor contentEncryptor)
throws CMSException
{
CMSEnvelopedData envContent = envGen.generate(keyContent, contentEncryptor);
EnvelopedData envD = EnvelopedData.getInstance(envContent.toASN1Structure().getContent());
return new PKIArchiveControl(new PKIArchiveOptions(new EncryptedKey(envD)));
}
示例9: generate
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
/**
* generate an enveloped object that contains an CMS Enveloped Data
* object using the given provider.
*
* @param content the content to be encrypted
* @param contentEncryptor the symmetric key based encryptor to encrypt the content with.
*/
public CMSEnvelopedData generate(
CMSTypedData content,
OutputEncryptor contentEncryptor)
throws CMSException
{
return doGenerate(content, contentEncryptor);
}
示例10: generate
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
/**
* generate an encrypted object that contains an CMS Encrypted Data structure.
*
* @param content the content to be encrypted
* @param contentEncryptor the symmetric key based encryptor to encrypt the content with.
*/
public CMSEncryptedData generate(
CMSTypedData content,
OutputEncryptor contentEncryptor)
throws CMSException
{
return doGenerate(content, contentEncryptor);
}
示例11: open
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
/**
* generate an enveloped object that contains an CMS Enveloped Data
* object using the given encryptor.
*/
public OutputStream open(
OutputStream out,
OutputEncryptor encryptor)
throws CMSException, IOException
{
return doOpen(new ASN1ObjectIdentifier(CMSObjectIdentifiers.data.getId()), out, encryptor);
}
示例12: generate
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
private PemObject generate(PrivateKeyInfo key, OutputEncryptor encryptor)
throws PemGenerationException
{
try
{
byte[] keyData = key.getEncoded();
if (encryptor == null)
{
return new PemObject("PRIVATE KEY", keyData);
}
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream cOut = encryptor.getOutputStream(bOut);
cOut.write(key.getEncoded());
cOut.close();
EncryptedPrivateKeyInfo info = new EncryptedPrivateKeyInfo(encryptor.getAlgorithmIdentifier(), bOut.toByteArray());
return new PemObject("ENCRYPTED PRIVATE KEY", info.getEncoded());
}
catch (IOException e)
{
throw new PemGenerationException("unable to process encoded key data: " + e.getMessage(), e);
}
}
示例13: build
import org.bouncycastle.operator.OutputEncryptor; //导入依赖的package包/类
public OutputEncryptor build(final char[] password)
{
if (random == null)
{
random = new SecureRandom();
}
final byte[] salt = new byte[20];
random.nextBytes(salt);
final PKCS12PBEParams pbeParams = new PKCS12PBEParams(salt, iterationCount);
CipherParameters params = PKCS12PBEUtils.createCipherParameters(algorithm, digest, engine.getBlockSize(), pbeParams, password);
engine.init(true, params);
return new OutputEncryptor()
{
public AlgorithmIdentifier getAlgorithmIdentifier()
{
return new AlgorithmIdentifier(algorithm, pbeParams);
}
public OutputStream getOutputStream(OutputStream out)
{
return new CipherOutputStream(out, engine);
}
public GenericKey getKey()
{
return new GenericKey(new AlgorithmIdentifier(algorithm, pbeParams), PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
}
};
}