FAES/AES/CryptUtils.cs
/// <summary>
/// Converts a string into a padded/truncated byte array
/// </summary>
/// <param name="value">String to convert</param>
/// <param name="limitLength">Limit the length of the password</param>
/// <param name="maxLength">Max length of the string</param>
/// <returns>Byte Array</returns>
Converts a string into a padded/truncated byte array
Converts a string into a padded / truncated byte array
public static byte[] ConvertStringToBytes(string value, bool limitLength = false, int maxLength = 64)
        {
            if (limitLength)
            {
                if (value.Length > maxLength)
                    return Encoding.UTF8.GetBytes(value.Substring(0, maxLength));
                else
                    return Encoding.UTF8.GetBytes(value.PadRight(maxLength, '\0'));
            }
            else return Encoding.UTF8.GetBytes(value);
        }
public static byte [ ] ConvertStringToBytes ( string value , bool limitLength = false , int maxLength = 64 ) { if ( limitLength ) { if ( value . Length > maxLength ) return Encoding . UTF8 . GetBytes ( value . Substring ( 0 , maxLength ) ) ; else return Encoding . UTF8 . GetBytes ( value . PadRight ( maxLength , ' \0 ' ) ) ; } else return Encoding . UTF8 . GetBytes ( value ) ; }
Converts a string into a padded/truncated byte array
Converts a string into a padded / truncated byte array
None
value
string
String to convert
String to convert
limitLength
bool
Limit the length of the password
Limit the length of the password
maxLength
int
Max length of the string
Max length of the string