123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- using System.Collections;
- using System.IO;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ntt;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Cms;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.IO;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Security;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
- namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators
- {
- public class Asn1CipherBuilderWithKey : ICipherBuilderWithKey
- {
- private readonly KeyParameter encKey;
- private AlgorithmIdentifier algorithmIdentifier;
- public Asn1CipherBuilderWithKey(DerObjectIdentifier encryptionOID, int keySize, SecureRandom random)
- {
- if (random == null)
- {
- random = new SecureRandom();
- }
- CipherKeyGenerator keyGen = CipherKeyGeneratorFactory.CreateKeyGenerator(encryptionOID, random);
- encKey = new KeyParameter(keyGen.GenerateKey());
- algorithmIdentifier = AlgorithmIdentifierFactory.GenerateEncryptionAlgID(encryptionOID, encKey.GetKey().Length * 8, random);
- }
- public object AlgorithmDetails
- {
- get { return algorithmIdentifier; }
- }
- public int GetMaxOutputSize(int inputLen)
- {
- throw new NotImplementedException();
- }
- public ICipher BuildCipher(Stream stream)
- {
- object cipher = EnvelopedDataHelper.CreateContentCipher(true, encKey, algorithmIdentifier);
- //
- // BufferedBlockCipher
- // IStreamCipher
- //
- if (cipher is IStreamCipher)
- {
- cipher = new BufferedStreamCipher((IStreamCipher)cipher);
- }
- if (stream == null)
- {
- stream = new MemoryStream();
- }
- return new BufferedCipherWrapper((IBufferedCipher)cipher, stream);
- }
- public ICipherParameters Key
- {
- get { return encKey; }
- }
- }
- public class BufferedCipherWrapper : ICipher
- {
- private readonly IBufferedCipher bufferedCipher;
- private readonly CipherStream stream;
- public BufferedCipherWrapper(IBufferedCipher bufferedCipher, Stream source)
- {
- this.bufferedCipher = bufferedCipher;
- stream = new CipherStream(source, bufferedCipher, bufferedCipher);
- }
- public int GetMaxOutputSize(int inputLen)
- {
- return bufferedCipher.GetOutputSize(inputLen);
- }
- public int GetUpdateOutputSize(int inputLen)
- {
- return bufferedCipher.GetUpdateOutputSize(inputLen);
- }
- public Stream Stream
- {
- get { return stream; }
- }
- }
- }
- #pragma warning restore
- #endif
|