PKCS5Scheme2PBEKey.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
  7. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
  8. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
  9. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
  10. {
  11. /// <summary>
  12. /// PKCS5 scheme-2 - password converted to bytes assuming ASCII.
  13. /// </summary>
  14. public class Pkcs5Scheme2PbeKey
  15. : CmsPbeKey
  16. {
  17. [Obsolete("Use version taking 'char[]' instead")]
  18. public Pkcs5Scheme2PbeKey(
  19. string password,
  20. byte[] salt,
  21. int iterationCount)
  22. : this(password.ToCharArray(), salt, iterationCount)
  23. {
  24. }
  25. [Obsolete("Use version taking 'char[]' instead")]
  26. public Pkcs5Scheme2PbeKey(
  27. string password,
  28. AlgorithmIdentifier keyDerivationAlgorithm)
  29. : this(password.ToCharArray(), keyDerivationAlgorithm)
  30. {
  31. }
  32. public Pkcs5Scheme2PbeKey(
  33. char[] password,
  34. byte[] salt,
  35. int iterationCount)
  36. : base(password, salt, iterationCount)
  37. {
  38. }
  39. public Pkcs5Scheme2PbeKey(
  40. char[] password,
  41. AlgorithmIdentifier keyDerivationAlgorithm)
  42. : base(password, keyDerivationAlgorithm)
  43. {
  44. }
  45. internal override KeyParameter GetEncoded(
  46. string algorithmOid)
  47. {
  48. Pkcs5S2ParametersGenerator gen = new Pkcs5S2ParametersGenerator();
  49. gen.Init(
  50. PbeParametersGenerator.Pkcs5PasswordToBytes(password),
  51. salt,
  52. iterationCount);
  53. return (KeyParameter) gen.GenerateDerivedParameters(
  54. algorithmOid,
  55. CmsEnvelopedHelper.Instance.GetKeySize(algorithmOid));
  56. }
  57. }
  58. }
  59. #pragma warning restore
  60. #endif