SubjectKeyIdentifierStructure.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Security.Certificates;
  8. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.X509.Extension
  9. {
  10. /**
  11. * A high level subject key identifier.
  12. */
  13. public class SubjectKeyIdentifierStructure
  14. : SubjectKeyIdentifier
  15. {
  16. /**
  17. * Constructor which will take the byte[] returned from getExtensionValue()
  18. *
  19. * @param encodedValue a DER octet encoded string with the extension structure in it.
  20. * @throws IOException on parsing errors.
  21. */
  22. public SubjectKeyIdentifierStructure(
  23. Asn1OctetString encodedValue)
  24. : base((Asn1OctetString) X509ExtensionUtilities.FromExtensionValue(encodedValue))
  25. {
  26. }
  27. private static Asn1OctetString FromPublicKey(
  28. AsymmetricKeyParameter pubKey)
  29. {
  30. try
  31. {
  32. SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(pubKey);
  33. return (Asn1OctetString) new SubjectKeyIdentifier(info).ToAsn1Object();
  34. }
  35. catch (Exception e)
  36. {
  37. throw new CertificateParsingException("Exception extracting certificate details: " + e.ToString());
  38. }
  39. }
  40. public SubjectKeyIdentifierStructure(
  41. AsymmetricKeyParameter pubKey)
  42. : base(FromPublicKey(pubKey))
  43. {
  44. }
  45. }
  46. }
  47. #pragma warning restore
  48. #endif