PKCS5Scheme2PBEKey.cs 1.6 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. public Pkcs5Scheme2PbeKey(
  18. string password,
  19. byte[] salt,
  20. int iterationCount)
  21. : this(password.ToCharArray(), salt, iterationCount)
  22. {
  23. }
  24. public Pkcs5Scheme2PbeKey(
  25. string password,
  26. AlgorithmIdentifier keyDerivationAlgorithm)
  27. : this(password.ToCharArray(), keyDerivationAlgorithm)
  28. {
  29. }
  30. public Pkcs5Scheme2PbeKey(
  31. char[] password,
  32. byte[] salt,
  33. int iterationCount)
  34. : base(password, salt, iterationCount)
  35. {
  36. }
  37. public Pkcs5Scheme2PbeKey(
  38. char[] password,
  39. AlgorithmIdentifier keyDerivationAlgorithm)
  40. : base(password, keyDerivationAlgorithm)
  41. {
  42. }
  43. internal override KeyParameter GetEncoded(
  44. string algorithmOid)
  45. {
  46. Pkcs5S2ParametersGenerator gen = new Pkcs5S2ParametersGenerator();
  47. gen.Init(
  48. PbeParametersGenerator.Pkcs5PasswordToBytes(password),
  49. salt,
  50. iterationCount);
  51. return (KeyParameter) gen.GenerateDerivedParameters(
  52. algorithmOid,
  53. CmsEnvelopedHelper.Instance.GetKeySize(algorithmOid));
  54. }
  55. }
  56. }
  57. #pragma warning restore
  58. #endif