PKCS12PBEParams.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs
  7. {
  8. public class Pkcs12PbeParams
  9. : Asn1Encodable
  10. {
  11. private readonly DerInteger iterations;
  12. private readonly Asn1OctetString iv;
  13. public Pkcs12PbeParams(
  14. byte[] salt,
  15. int iterations)
  16. {
  17. this.iv = new DerOctetString(salt);
  18. this.iterations = new DerInteger(iterations);
  19. }
  20. private Pkcs12PbeParams(
  21. Asn1Sequence seq)
  22. {
  23. if (seq.Count != 2)
  24. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  25. iv = Asn1OctetString.GetInstance(seq[0]);
  26. iterations = DerInteger.GetInstance(seq[1]);
  27. }
  28. public static Pkcs12PbeParams GetInstance(
  29. object obj)
  30. {
  31. if (obj is Pkcs12PbeParams)
  32. {
  33. return (Pkcs12PbeParams) obj;
  34. }
  35. if (obj is Asn1Sequence)
  36. {
  37. return new Pkcs12PbeParams((Asn1Sequence) obj);
  38. }
  39. throw new ArgumentException("Unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  40. }
  41. public BigInteger Iterations
  42. {
  43. get { return iterations.Value; }
  44. }
  45. public byte[] GetIV()
  46. {
  47. return iv.GetOctets();
  48. }
  49. public override Asn1Object ToAsn1Object()
  50. {
  51. return new DerSequence(iv, iterations);
  52. }
  53. }
  54. }
  55. #pragma warning restore
  56. #endif