c#

时间:2017-06-27 14:29:27

标签: c# encryption aes

我只收到一个密钥和一个使用AES加密的值。我现在需要解密它并从中检索值。但是我在网上找到的所有样品都使用其他属性来解密(盐,IV,...)

我在网上看到了这个网站http://aes.online-domain-tools.com/,我可以将其解密为二进制文件。

但是在c#中这样做似乎对我不起作用。

有人能为我提供一种简单的方法,只用加密值和密钥在c#中解密AES_128吗?

修改

  1. 从密钥中检索IV:

    Key = System.Text.Encoding.ASCII.GetBytes(DecryptionConstants.AES_KEY);
    using (Aes aesAlg = Aes.Create())
    {
        // Convert Key to bytes and pass into AES
        aesAlg.Key = Convert.FromBase64String(DecryptionConstants.AES_KEY);
        IV = new byte[aesAlg.BlockSize / 8];
    
        var hexKey = BitConverter.ToString(IV);
        IV = StringToByteArray("a2 26 cb 78 e2 cb 26 cb e7 c7 f0 bc c7 7b bd 9d");
    
    }
    
  2. 解密

    byte[] EncryptedBytes = Convert.FromBase64String(text);
    
    //Setup the AES provider for decrypting.            
    AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider
    {
        Key = Key,
        IV = this.IV,
        BlockSize = 128,
        KeySize = 256,
        Padding = PaddingMode.None,
        Mode = CipherMode.CBC,                
    };
    
    var cryptoTransform = aesProvider.CreateDecryptor(aesProvider.Key, aesProvider.IV);
    
    var DecryptedBytes = cryptoTransform.TransformFinalBlock(EncryptedBytes, 8, EncryptedBytes.Length-8);
    
  3. 这导致一个字节数组,它决不会被带回我输入的字符串。

1 个答案:

答案 0 :(得分:0)

使用您的数据,您应该猜测IV,可能是16个零或前16个字节的数据,以及CipherMode,ECB,CBC左右。

这是我用来加密/解密的一个小功能:

emailChanged
相关问题