PasswordConverter
Standard char[] to byte[] converters for password based derivation algorithms.
namespace Org.BouncyCastle.Crypto
{
public sealed class PasswordConverter : ICharToByteConverter
{
private delegate byte[] ConverterFunction (char[] password);
private readonly string m_name;
private readonly ConverterFunction m_converterFunction;
public static readonly ICharToByteConverter Ascii = new PasswordConverter("ASCII", PbeParametersGenerator.Pkcs5PasswordToBytes);
public static readonly ICharToByteConverter Utf8 = new PasswordConverter("UTF8", PbeParametersGenerator.Pkcs5PasswordToUtf8Bytes);
public static readonly ICharToByteConverter Pkcs12 = new PasswordConverter("PKCS12", PbeParametersGenerator.Pkcs12PasswordToBytes);
public string Name => m_name;
private PasswordConverter(string name, ConverterFunction converterFunction)
{
m_name = name;
m_converterFunction = converterFunction;
}
public byte[] Convert(char[] password)
{
return m_converterFunction(password);
}
}
}