首页 > 代码库 > C# TripleDES NoPadding 时对待加密内容进行补字节(8个字节为一个Block)

C# TripleDES NoPadding 时对待加密内容进行补字节(8个字节为一个Block)

补一个空格(半角):

private static byte[] FormatData(String str)
{
    var yu = str.Length % 8;
    if (yu == 0) return Encoding.GetEncoding(Consts.Charset).GetBytes(str);
    var size = 8 - yu;
    var arr = new byte[str.Length + size];
    var data =http://www.mamicode.com/ Encoding.GetEncoding(Consts.Charset).GetBytes(str);
    var i = 0;
    for (; i < data.Length; i++)
    {
        arr[i] = data[i];
    }
    for (var j = 0; j < size; j++,i++)
    {
        arr[i] = Convert.ToByte( );
    }
    return arr;
}

private static byte[] FormatByte(IList<byte> arr)
{
    var i = 0;
    for (; i < arr.Count; i++)
    {
        if (Convert.ToChar(arr[i]) ==  )
        {
            break;
        }
    }
    var result = new byte[i];
    for (var j = 0; j < i; j++)
    {
        result[j] = arr[j];
    }
    return result;
}

 

C# TripleDES NoPadding 时对待加密内容进行补字节(8个字节为一个Block)