本文整理汇总了C#中Org.BouncyCastle.Asn1.X509.AlgorithmIdentifier.GetEncoded方法的典型用法代码示例。如果您正苦于以下问题:C# AlgorithmIdentifier.GetEncoded方法的具体用法?C# AlgorithmIdentifier.GetEncoded怎么用?C# AlgorithmIdentifier.GetEncoded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org.BouncyCastle.Asn1.X509.AlgorithmIdentifier
的用法示例。
在下文中一共展示了AlgorithmIdentifier.GetEncoded方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Open
protected Stream Open(
Stream outStream,
string encryptionOid,
KeyParameter encKey,
Asn1Encodable asn1Params,
Asn1EncodableVector recipientInfos)
{
Asn1Object asn1Object;
ICipherParameters cipherParameters;
if (asn1Params != null)
{
asn1Object = asn1Params.ToAsn1Object();
cipherParameters = ParameterUtilities.GetCipherParameters(
encryptionOid, encKey, asn1Object);
}
else
{
asn1Object = DerNull.Instance;
cipherParameters = encKey;
}
try
{
AlgorithmIdentifier encAlgId = new AlgorithmIdentifier(
new DerObjectIdentifier(encryptionOid),
asn1Object);
//
// ContentInfo
//
BerSequenceGenerator cGen = new BerSequenceGenerator(outStream);
cGen.AddObject(CmsObjectIdentifiers.EnvelopedData);
//
// Encrypted Data
//
BerSequenceGenerator envGen = new BerSequenceGenerator(
cGen.GetRawOutputStream(), 0, true);
envGen.AddObject(this.Version);
DerSet derSet = _berEncodeRecipientSet
? new BerSet(recipientInfos)
: new DerSet(recipientInfos);
byte[] derSetEncoding = derSet.GetEncoded();
envGen.GetRawOutputStream().Write(derSetEncoding, 0, derSetEncoding.Length);
IBufferedCipher cipher = CipherUtilities.GetCipher(encryptionOid);
cipher.Init(true, cipherParameters);
BerSequenceGenerator eiGen = new BerSequenceGenerator(
envGen.GetRawOutputStream());
eiGen.AddObject(PkcsObjectIdentifiers.Data);
byte[] tmp = encAlgId.GetEncoded();
eiGen.GetRawOutputStream().Write(tmp, 0, tmp.Length);
BerOctetStringGenerator octGen = new BerOctetStringGenerator(
eiGen.GetRawOutputStream(), 0, false);
Stream octetOutputStream = _bufferSize != 0
? octGen.GetOctetOutputStream(new byte[_bufferSize])
: octGen.GetOctetOutputStream();
CipherStream cOut = new CipherStream(octetOutputStream, null, cipher);
return new CmsEnvelopedDataOutputStream(cOut, cGen, envGen, eiGen);
}
catch (SecurityUtilityException e)
{
throw new CmsException("couldn't create cipher.", e);
}
catch (InvalidKeyException e)
{
throw new CmsException("key invalid in message.", e);
}
catch (IOException e)
{
throw new CmsException("exception decoding algorithm parameters.", e);
}
}