KeyTransRecipientInfo.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms
  7. {
  8. public class KeyTransRecipientInfo
  9. : Asn1Encodable
  10. {
  11. private DerInteger version;
  12. private RecipientIdentifier rid;
  13. private AlgorithmIdentifier keyEncryptionAlgorithm;
  14. private Asn1OctetString encryptedKey;
  15. public KeyTransRecipientInfo(
  16. RecipientIdentifier rid,
  17. AlgorithmIdentifier keyEncryptionAlgorithm,
  18. Asn1OctetString encryptedKey)
  19. {
  20. if (rid.ToAsn1Object() is Asn1TaggedObject)
  21. {
  22. this.version = new DerInteger(2);
  23. }
  24. else
  25. {
  26. this.version = new DerInteger(0);
  27. }
  28. this.rid = rid;
  29. this.keyEncryptionAlgorithm = keyEncryptionAlgorithm;
  30. this.encryptedKey = encryptedKey;
  31. }
  32. public KeyTransRecipientInfo(
  33. Asn1Sequence seq)
  34. {
  35. this.version = (DerInteger) seq[0];
  36. this.rid = RecipientIdentifier.GetInstance(seq[1]);
  37. this.keyEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[2]);
  38. this.encryptedKey = (Asn1OctetString) seq[3];
  39. }
  40. /**
  41. * return a KeyTransRecipientInfo object from the given object.
  42. *
  43. * @param obj the object we want converted.
  44. * @exception ArgumentException if the object cannot be converted.
  45. */
  46. public static KeyTransRecipientInfo GetInstance(
  47. object obj)
  48. {
  49. if (obj == null || obj is KeyTransRecipientInfo)
  50. return (KeyTransRecipientInfo) obj;
  51. if(obj is Asn1Sequence)
  52. return new KeyTransRecipientInfo((Asn1Sequence) obj);
  53. throw new ArgumentException(
  54. "Illegal object in KeyTransRecipientInfo: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
  55. }
  56. public DerInteger Version
  57. {
  58. get { return version; }
  59. }
  60. public RecipientIdentifier RecipientIdentifier
  61. {
  62. get { return rid; }
  63. }
  64. public AlgorithmIdentifier KeyEncryptionAlgorithm
  65. {
  66. get { return keyEncryptionAlgorithm; }
  67. }
  68. public Asn1OctetString EncryptedKey
  69. {
  70. get { return encryptedKey; }
  71. }
  72. /**
  73. * Produce an object suitable for an Asn1OutputStream.
  74. * <pre>
  75. * KeyTransRecipientInfo ::= Sequence {
  76. * version CMSVersion, -- always set to 0 or 2
  77. * rid RecipientIdentifier,
  78. * keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
  79. * encryptedKey EncryptedKey
  80. * }
  81. * </pre>
  82. */
  83. public override Asn1Object ToAsn1Object()
  84. {
  85. return new DerSequence(version, rid, keyEncryptionAlgorithm, encryptedKey);
  86. }
  87. }
  88. }
  89. #pragma warning restore
  90. #endif