CmsContentEncryptorBuilder.cs 2.5 KB

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