Ejemplo n.º 1
0
 public static byte[] AesDecode(byte[] Aesfile, string Key)
 {
     byte[] DecryptBytes;
     using (AesManaged aes = new AesManaged())
     {
         using (EncryptHelp help = new EncryptHelp())
         {
             aes.BlockSize = aes.LegalBlockSizes[0].MaxSize;
             aes.KeySize   = aes.LegalKeySizes[0].MaxSize;
             aes.IV        = GetAesKey(aes.BlockSize / 8, help.Salt1, Key.SHA256HashString());
             aes.Key       = GetAesKey(aes.KeySize / 8, help.Salt2, Key.SHA256HashString());
             aes.IV.PrintByteArray();
             aes.Key.PrintByteArray();
             DecryptBytes = DecryptBytesFromBytes_Aes(Aesfile, aes.Key, aes.IV);
         }
     }
     return(DecryptBytes);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 解密由Aes算法加密的Byte[]
 /// </summary>
 /// <param name="file"></param>
 /// <param name="Key"></param>
 /// <returns>返回一个解密后的Byte[]</returns>
 public static byte[] AesEncode(this byte[] file, string Key)
 {
     byte[] encryptedByte;
     using (AesManaged aes = new AesManaged())
     {
         using (EncryptHelp help = new EncryptHelp())
         {
             aes.BlockSize = aes.LegalBlockSizes[0].MaxSize;
             aes.KeySize   = aes.LegalKeySizes[0].MaxSize;
             aes.IV        = GetAesKey(aes.BlockSize / 8, help.Salt1, Key.SHA256HashString());
             aes.Key       = GetAesKey(aes.KeySize / 8, help.Salt2, Key.SHA256HashString());
             aes.IV.PrintByteArray();
             aes.Key.PrintByteArray();
             encryptedByte = EncryptBytesToBytes_Aes(file, aes.Key, aes.IV);
         }
     }
     return(encryptedByte);
 }