PbmParameter.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.Cmp
  7. {
  8. public class PbmParameter
  9. : Asn1Encodable
  10. {
  11. private Asn1OctetString salt;
  12. private AlgorithmIdentifier owf;
  13. private DerInteger iterationCount;
  14. private AlgorithmIdentifier mac;
  15. private PbmParameter(Asn1Sequence seq)
  16. {
  17. salt = Asn1OctetString.GetInstance(seq[0]);
  18. owf = AlgorithmIdentifier.GetInstance(seq[1]);
  19. iterationCount = DerInteger.GetInstance(seq[2]);
  20. mac = AlgorithmIdentifier.GetInstance(seq[3]);
  21. }
  22. public static PbmParameter GetInstance(object obj)
  23. {
  24. if (obj is PbmParameter)
  25. return (PbmParameter)obj;
  26. if (obj is Asn1Sequence)
  27. return new PbmParameter((Asn1Sequence)obj);
  28. throw new ArgumentException("Invalid object: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  29. }
  30. public PbmParameter(
  31. byte[] salt,
  32. AlgorithmIdentifier owf,
  33. int iterationCount,
  34. AlgorithmIdentifier mac)
  35. : this(new DerOctetString(salt), owf, new DerInteger(iterationCount), mac)
  36. {
  37. }
  38. public PbmParameter(
  39. Asn1OctetString salt,
  40. AlgorithmIdentifier owf,
  41. DerInteger iterationCount,
  42. AlgorithmIdentifier mac)
  43. {
  44. this.salt = salt;
  45. this.owf = owf;
  46. this.iterationCount = iterationCount;
  47. this.mac = mac;
  48. }
  49. public virtual Asn1OctetString Salt
  50. {
  51. get { return salt; }
  52. }
  53. public virtual AlgorithmIdentifier Owf
  54. {
  55. get { return owf; }
  56. }
  57. public virtual DerInteger IterationCount
  58. {
  59. get { return iterationCount; }
  60. }
  61. public virtual AlgorithmIdentifier Mac
  62. {
  63. get { return mac; }
  64. }
  65. /**
  66. * <pre>
  67. * PbmParameter ::= SEQUENCE {
  68. * salt OCTET STRING,
  69. * -- note: implementations MAY wish to limit acceptable sizes
  70. * -- of this string to values appropriate for their environment
  71. * -- in order to reduce the risk of denial-of-service attacks
  72. * owf AlgorithmIdentifier,
  73. * -- AlgId for a One-Way Function (SHA-1 recommended)
  74. * iterationCount INTEGER,
  75. * -- number of times the OWF is applied
  76. * -- note: implementations MAY wish to limit acceptable sizes
  77. * -- of this integer to values appropriate for their environment
  78. * -- in order to reduce the risk of denial-of-service attacks
  79. * mac AlgorithmIdentifier
  80. * -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
  81. * } -- or HMAC [RFC2104, RFC2202])
  82. * </pre>
  83. * @return a basic ASN.1 object representation.
  84. */
  85. public override Asn1Object ToAsn1Object()
  86. {
  87. return new DerSequence(salt, owf, iterationCount, mac);
  88. }
  89. }
  90. }
  91. #pragma warning restore
  92. #endif