123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- using System.IO;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
- namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
- {
- public abstract class RecipientInformation
- {
- internal RecipientID rid = new RecipientID();
- internal AlgorithmIdentifier keyEncAlg;
- internal CmsSecureReadable secureReadable;
-
- private byte[] resultMac;
- internal RecipientInformation(
- AlgorithmIdentifier keyEncAlg,
- CmsSecureReadable secureReadable)
- {
- this.keyEncAlg = keyEncAlg;
- this.secureReadable = secureReadable;
- }
- internal string GetContentAlgorithmName()
- {
- AlgorithmIdentifier algorithm = secureReadable.Algorithm;
- // return CmsEnvelopedHelper.Instance.GetSymmetricCipherName(algorithm.Algorithm.Id);
- return algorithm.Algorithm.Id;
- }
- public RecipientID RecipientID
- {
- get { return rid; }
- }
- public AlgorithmIdentifier KeyEncryptionAlgorithmID
- {
- get { return keyEncAlg; }
- }
- /**
- * return the object identifier for the key encryption algorithm.
- *
- * @return OID for key encryption algorithm.
- */
- public string KeyEncryptionAlgOid
- {
- get { return keyEncAlg.Algorithm.Id; }
- }
- /**
- * return the ASN.1 encoded key encryption algorithm parameters, or null if
- * there aren't any.
- *
- * @return ASN.1 encoding of key encryption algorithm parameters.
- */
- public Asn1Object KeyEncryptionAlgParams
- {
- get
- {
- Asn1Encodable ae = keyEncAlg.Parameters;
- return ae == null ? null : ae.ToAsn1Object();
- }
- }
- internal CmsTypedStream GetContentFromSessionKey(
- KeyParameter sKey)
- {
- CmsReadable readable = secureReadable.GetReadable(sKey);
- try
- {
- return new CmsTypedStream(readable.GetInputStream());
- }
- catch (IOException e)
- {
- throw new CmsException("error getting .", e);
- }
- }
- public byte[] GetContent(
- ICipherParameters key)
- {
- try
- {
- return CmsUtilities.StreamToByteArray(GetContentStream(key).ContentStream);
- }
- catch (IOException e)
- {
- throw new Exception("unable to parse internal stream: " + e);
- }
- }
- /**
- * Return the MAC calculated for the content stream. Note: this call is only meaningful once all
- * the content has been read.
- *
- * @return byte array containing the mac.
- */
- public byte[] GetMac()
- {
- if (resultMac == null)
- {
- object cryptoObject = secureReadable.CryptoObject;
- if (cryptoObject is IMac)
- {
- resultMac = MacUtilities.DoFinal((IMac)cryptoObject);
- }
- }
- return Arrays.Clone(resultMac);
- }
-
- public abstract CmsTypedStream GetContentStream(ICipherParameters key);
- }
- }
- #pragma warning restore
- #endif
|