Загрузка...

Методы шифрования

Тема в разделе C# создана пользователем aysman 7 мар 2018. 169 просмотров

Загрузка...
  1. aysman
    aysman Автор темы 7 мар 2018 0 17 сен 2017
    Код
     public byte[] RSMEncrypt(byte[] input, byte[] key)

    {
    Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(key, new byte[8], 1);
    RijndaelManaged rijndaelManaged = new RijndaelManaged();
    rijndaelManaged.Key = rfc2898DeriveBytes.GetBytes(16);
    rijndaelManaged.IV = rfc2898DeriveBytes.GetBytes(16);
    byte[] array = new byte[input.Length + 16];
    Buffer.BlockCopy(Guid.NewGuid().ToByteArray(), 0, array, 0, 16);
    Buffer.BlockCopy(input, 0, array, 16, input.Length);
    return rijndaelManaged.CreateEncryptor().TransformFinalBlock(array, 0, array.Length);
    }
    public byte[] RSMDecrypt(byte[] data, byte[] key)
    {
    Rfc2898DeriveBytes R = new Rfc2898DeriveBytes(key, new byte[8], 1);
    RijndaelManaged T = new RijndaelManaged();
    T.Key = R.GetBytes(16);
    T.IV = R.GetBytes(16);
    byte[] O = T.CreateDecryptor().TransformFinalBlock(data, 0, data.Length);
    byte[] U = new byte[O.Length - 16];
    Buffer.BlockCopy(O, 16, U, 0, O.Length - 16);
    return U;
    }
     
Top