本文整理汇总了C#中Org.BouncyCastle.Asn1.Asn1Encodable.ToAsn1Object方法的典型用法代码示例。如果您正苦于以下问题:C# Asn1Encodable.ToAsn1Object方法的具体用法?C# Asn1Encodable.ToAsn1Object怎么用?C# Asn1Encodable.ToAsn1Object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org.BouncyCastle.Asn1.Asn1Encodable
的用法示例。
在下文中一共展示了Asn1Encodable.ToAsn1Object方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteObject
public virtual void WriteObject(
Asn1Encodable obj)
{
if (obj == null)
{
WriteNull();
}
else
{
obj.ToAsn1Object().Encode(this);
}
}
示例2: SmimeCapability
public SmimeCapability(
DerObjectIdentifier capabilityID,
Asn1Encodable parameters)
{
if (capabilityID == null)
throw new ArgumentNullException("capabilityID");
this.capabilityID = capabilityID;
if (parameters != null)
{
this.parameters = parameters.ToAsn1Object();
}
}
示例3: CommitmentTypeQualifier
/**
* Creates a new <code>CommitmentTypeQualifier</code> instance.
*
* @param commitmentTypeIdentifier a <code>CommitmentTypeIdentifier</code> value
* @param qualifier the qualifier, defined by the above field.
*/
public CommitmentTypeQualifier(
DerObjectIdentifier commitmentTypeIdentifier,
Asn1Encodable qualifier)
{
if (commitmentTypeIdentifier == null)
throw new ArgumentNullException("commitmentTypeIdentifier");
this.commitmentTypeIdentifier = commitmentTypeIdentifier;
if (qualifier != null)
{
this.qualifier = qualifier.ToAsn1Object();
}
}
示例4: DerApplicationSpecific
public DerApplicationSpecific(
bool isExplicit,
int tag,
Asn1Encodable obj)
{
Asn1Object asn1Obj = obj.ToAsn1Object();
byte[] data = asn1Obj.GetDerEncoded();
this.isConstructed = isExplicit || asn1Obj is Asn1Set || asn1Obj is Asn1Sequence;
this.tag = tag;
if (isExplicit)
{
this.octets = data;
}
else
{
int lenBytes = GetLengthOfHeader(data);
byte[] tmp = new byte[data.Length - lenBytes];
Array.Copy(data, lenBytes, tmp, 0, tmp.Length);
this.octets = tmp;
}
}
示例5: GenerateCipherParameters
public static ICipherParameters GenerateCipherParameters(
string algorithm,
char[] password,
bool wrongPkcs12Zero,
Asn1Encodable pbeParameters)
{
string mechanism = (string) algorithms[algorithm.ToUpperInvariant()];
byte[] keyBytes = null;
byte[] salt = null;
int iterationCount = 0;
if (IsPkcs12(mechanism))
{
Pkcs12PbeParams pbeParams = Pkcs12PbeParams.GetInstance(pbeParameters);
salt = pbeParams.GetIV();
iterationCount = pbeParams.Iterations.IntValue;
keyBytes = PbeParametersGenerator.Pkcs12PasswordToBytes(password, wrongPkcs12Zero);
}
else if (IsPkcs5Scheme2(mechanism))
{
// See below
}
else
{
PbeParameter pbeParams = PbeParameter.GetInstance(pbeParameters);
salt = pbeParams.GetSalt();
iterationCount = pbeParams.IterationCount.IntValue;
keyBytes = PbeParametersGenerator.Pkcs5PasswordToBytes(password);
}
ICipherParameters parameters = null;
if (IsPkcs5Scheme2(mechanism))
{
PbeS2Parameters s2p = PbeS2Parameters.GetInstance(pbeParameters.ToAsn1Object());
AlgorithmIdentifier encScheme = s2p.EncryptionScheme;
DerObjectIdentifier encOid = encScheme.ObjectID;
Asn1Object encParams = encScheme.Parameters.ToAsn1Object();
// TODO What about s2p.KeyDerivationFunc.ObjectID?
Pbkdf2Params pbeParams = Pbkdf2Params.GetInstance(s2p.KeyDerivationFunc.Parameters.ToAsn1Object());
byte[] iv;
if (encOid.Equals(PkcsObjectIdentifiers.RC2Cbc)) // PKCS5.B.2.3
{
RC2CbcParameter rc2Params = RC2CbcParameter.GetInstance(encParams);
iv = rc2Params.GetIV();
}
else
{
iv = Asn1OctetString.GetInstance(encParams).GetOctets();
}
salt = pbeParams.GetSalt();
iterationCount = pbeParams.IterationCount.IntValue;
keyBytes = PbeParametersGenerator.Pkcs5PasswordToBytes(password);
int keyLength = pbeParams.KeyLength != null
? pbeParams.KeyLength.IntValue * 8
: GeneratorUtilities.GetDefaultKeySize(encOid);
PbeParametersGenerator gen = MakePbeGenerator(
(string)algorithmType[mechanism], null, keyBytes, salt, iterationCount);
parameters = gen.GenerateDerivedParameters(encOid.Id, keyLength);
if (iv != null)
{
// FIXME? OpenSSL weirdness with IV of zeros (for ECB keys?)
if (Arrays.AreEqual(iv, new byte[iv.Length]))
{
//System.Diagnostics.Debug.Error.Write("***** IV all 0 (length " + iv.Length + ") *****");
}
else
{
parameters = new ParametersWithIV(parameters, iv);
}
}
}
else if (mechanism.StartsWith("PBEwithSHA-1"))
{
PbeParametersGenerator generator = MakePbeGenerator(
(string) algorithmType[mechanism], new Sha1Digest(), keyBytes, salt, iterationCount);
if (mechanism.Equals("PBEwithSHA-1and128bitRC4"))
{
parameters = generator.GenerateDerivedParameters("RC4", 128);
}
else if (mechanism.Equals("PBEwithSHA-1and40bitRC4"))
{
parameters = generator.GenerateDerivedParameters("RC4", 40);
}
else if (mechanism.Equals("PBEwithSHA-1and3-keyDESEDE-CBC"))
{
parameters = generator.GenerateDerivedParameters("DESEDE", 192, 64);
}
else if (mechanism.Equals("PBEwithSHA-1and2-keyDESEDE-CBC"))
{
parameters = generator.GenerateDerivedParameters("DESEDE", 128, 64);
//.........这里部分代码省略.........
示例6: BerOctetString
public BerOctetString(
Asn1Encodable obj)
: base(obj.ToAsn1Object())
{
}
示例7: AttCertIssuer
/// <summary>
/// Don't use this one if you are trying to be RFC 3281 compliant.
/// Use it for v1 attribute certificates only.
/// </summary>
/// <param name="names">Our GeneralNames structure</param>
public AttCertIssuer(
GeneralNames names)
{
obj = names;
choiceObj = obj.ToAsn1Object();
}
示例8: 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);
}
}