EncryptedPrivateKeyInfo.cs 2.1 KB

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