123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- using System;
- using System.Text;
- using Org.BouncyCastle.Utilities;
- namespace Org.BouncyCastle.Crypto
- {
-
- public abstract class PbeParametersGenerator
- {
- protected byte[] mPassword;
- protected byte[] mSalt;
- protected int mIterationCount;
-
- protected PbeParametersGenerator()
- {
- }
-
- public virtual void Init(
- byte[] password,
- byte[] salt,
- int iterationCount)
- {
- if (password == null)
- throw new ArgumentNullException("password");
- if (salt == null)
- throw new ArgumentNullException("salt");
- this.mPassword = Arrays.Clone(password);
- this.mSalt = Arrays.Clone(salt);
- this.mIterationCount = iterationCount;
- }
- public virtual byte[] Password
- {
- get { return Arrays.Clone(mPassword); }
- }
-
- [Obsolete("Use 'Password' property")]
- public byte[] GetPassword()
- {
- return Password;
- }
- public virtual byte[] Salt
- {
- get { return Arrays.Clone(mSalt); }
- }
-
- [Obsolete("Use 'Salt' property")]
- public byte[] GetSalt()
- {
- return Salt;
- }
-
- public virtual int IterationCount
- {
- get { return mIterationCount; }
- }
-
- [Obsolete("Use version with 'algorithm' parameter")]
- public abstract ICipherParameters GenerateDerivedParameters(int keySize);
- public abstract ICipherParameters GenerateDerivedParameters(string algorithm, int keySize);
-
- [Obsolete("Use version with 'algorithm' parameter")]
- public abstract ICipherParameters GenerateDerivedParameters(int keySize, int ivSize);
- public abstract ICipherParameters GenerateDerivedParameters(string algorithm, int keySize, int ivSize);
-
- public abstract ICipherParameters GenerateDerivedMacParameters(int keySize);
-
- public static byte[] Pkcs5PasswordToBytes(
- char[] password)
- {
- if (password == null)
- return new byte[0];
- return Strings.ToByteArray(password);
- }
- [Obsolete("Use version taking 'char[]' instead")]
- public static byte[] Pkcs5PasswordToBytes(
- string password)
- {
- if (password == null)
- return new byte[0];
- return Strings.ToByteArray(password);
- }
-
- public static byte[] Pkcs5PasswordToUtf8Bytes(
- char[] password)
- {
- if (password == null)
- return new byte[0];
- return Encoding.UTF8.GetBytes(password);
- }
- [Obsolete("Use version taking 'char[]' instead")]
- public static byte[] Pkcs5PasswordToUtf8Bytes(
- string password)
- {
- if (password == null)
- return new byte[0];
- return Encoding.UTF8.GetBytes(password);
- }
-
- public static byte[] Pkcs12PasswordToBytes(
- char[] password)
- {
- return Pkcs12PasswordToBytes(password, false);
- }
- public static byte[] Pkcs12PasswordToBytes(
- char[] password,
- bool wrongPkcs12Zero)
- {
- if (password == null || password.Length < 1)
- {
- return new byte[wrongPkcs12Zero ? 2 : 0];
- }
-
- byte[] bytes = new byte[(password.Length + 1) * 2];
- Encoding.BigEndianUnicode.GetBytes(password, 0, password.Length, bytes, 0);
- return bytes;
- }
- }
- }
- #endif
|