PKCS5Scheme2UTF8PBEKey.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
  7. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Generators;
  8. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
  9. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Cms
  10. {
  11. /**
  12. * PKCS5 scheme-2 - password converted to bytes using UTF-8.
  13. */
  14. public class Pkcs5Scheme2Utf8PbeKey
  15. : CmsPbeKey
  16. {
  17. public Pkcs5Scheme2Utf8PbeKey(
  18. char[] password,
  19. byte[] salt,
  20. int iterationCount)
  21. : base(password, salt, iterationCount)
  22. {
  23. }
  24. public Pkcs5Scheme2Utf8PbeKey(
  25. char[] password,
  26. AlgorithmIdentifier keyDerivationAlgorithm)
  27. : base(password, keyDerivationAlgorithm)
  28. {
  29. }
  30. internal override KeyParameter GetEncoded(
  31. string algorithmOid)
  32. {
  33. Pkcs5S2ParametersGenerator gen = new Pkcs5S2ParametersGenerator();
  34. gen.Init(
  35. PbeParametersGenerator.Pkcs5PasswordToUtf8Bytes(password),
  36. salt,
  37. iterationCount);
  38. return (KeyParameter) gen.GenerateDerivedParameters(
  39. algorithmOid,
  40. CmsEnvelopedHelper.Instance.GetKeySize(algorithmOid));
  41. }
  42. }
  43. }
  44. #pragma warning restore
  45. #endif