EncryptedPrivateKeyInfo.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs
  8. {
  9. public class EncryptedPrivateKeyInfo
  10. : Asn1Encodable
  11. {
  12. private readonly AlgorithmIdentifier algId;
  13. private readonly Asn1OctetString data;
  14. private EncryptedPrivateKeyInfo(
  15. Asn1Sequence seq)
  16. {
  17. if (seq.Count != 2)
  18. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  19. algId = AlgorithmIdentifier.GetInstance(seq[0]);
  20. data = Asn1OctetString.GetInstance(seq[1]);
  21. }
  22. public EncryptedPrivateKeyInfo(
  23. AlgorithmIdentifier algId,
  24. byte[] encoding)
  25. {
  26. this.algId = algId;
  27. this.data = new DerOctetString(encoding);
  28. }
  29. public static EncryptedPrivateKeyInfo GetInstance(
  30. object obj)
  31. {
  32. if (obj is EncryptedPrivateKeyInfo)
  33. {
  34. return (EncryptedPrivateKeyInfo) obj;
  35. }
  36. if (obj is Asn1Sequence)
  37. {
  38. return new EncryptedPrivateKeyInfo((Asn1Sequence) obj);
  39. }
  40. throw new ArgumentException("Unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  41. }
  42. public AlgorithmIdentifier EncryptionAlgorithm
  43. {
  44. get { return algId; }
  45. }
  46. public byte[] GetEncryptedData()
  47. {
  48. return data.GetOctets();
  49. }
  50. /**
  51. * Produce an object suitable for an Asn1OutputStream.
  52. * <pre>
  53. * EncryptedPrivateKeyInfo ::= Sequence {
  54. * encryptionAlgorithm AlgorithmIdentifier {{KeyEncryptionAlgorithms}},
  55. * encryptedData EncryptedData
  56. * }
  57. *
  58. * EncryptedData ::= OCTET STRING
  59. *
  60. * KeyEncryptionAlgorithms ALGORITHM-IDENTIFIER ::= {
  61. * ... -- For local profiles
  62. * }
  63. * </pre>
  64. */
  65. public override Asn1Object ToAsn1Object()
  66. {
  67. return new DerSequence(algId, data);
  68. }
  69. }
  70. }
  71. #pragma warning restore
  72. #endif