CmsContentEncryptorBuilder.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections.Generic;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Nist;
  7. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Ntt;
  8. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Cms;
  9. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
  10. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Operators;
  11. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Operators
  12. {
  13. public class CmsContentEncryptorBuilder
  14. {
  15. private static readonly IDictionary<DerObjectIdentifier, int> KeySizes =
  16. new Dictionary<DerObjectIdentifier, int>();
  17. static CmsContentEncryptorBuilder()
  18. {
  19. KeySizes[NistObjectIdentifiers.IdAes128Cbc] = 128;
  20. KeySizes[NistObjectIdentifiers.IdAes192Cbc] = 192;
  21. KeySizes[NistObjectIdentifiers.IdAes256Cbc] = 256;
  22. KeySizes[NttObjectIdentifiers.IdCamellia128Cbc] = 128;
  23. KeySizes[NttObjectIdentifiers.IdCamellia192Cbc] = 192;
  24. KeySizes[NttObjectIdentifiers.IdCamellia256Cbc] = 256;
  25. }
  26. private static int GetKeySize(DerObjectIdentifier oid)
  27. {
  28. return KeySizes.TryGetValue(oid, out var keySize) ? keySize : -1;
  29. }
  30. private readonly DerObjectIdentifier encryptionOID;
  31. private readonly int keySize;
  32. private readonly EnvelopedDataHelper helper = new EnvelopedDataHelper();
  33. //private SecureRandom random;
  34. public CmsContentEncryptorBuilder(DerObjectIdentifier encryptionOID)
  35. : this(encryptionOID, GetKeySize(encryptionOID))
  36. {
  37. }
  38. public CmsContentEncryptorBuilder(DerObjectIdentifier encryptionOID, int keySize)
  39. {
  40. this.encryptionOID = encryptionOID;
  41. this.keySize = keySize;
  42. }
  43. public ICipherBuilderWithKey Build()
  44. {
  45. //return new Asn1CipherBuilderWithKey(encryptionOID, keySize, random);
  46. return new Asn1CipherBuilderWithKey(encryptionOID, keySize, null);
  47. }
  48. }
  49. }
  50. #pragma warning restore
  51. #endif