123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System.IO;
- using System.Security.Cryptography;
- namespace YOLODetectProcessLib
- {
- /// <summary>
- /// 用AES法加密解密
- /// </summary>
- public class AES
- {
- private static byte[] _iv = new byte[] { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
- private static byte[] _key = new byte[] { 0x11, 0x21, 0x12, 0x22, 0x31, 0x32, 0x02, 0x03, 0x11, 0x21, 0x12, 0x22, 0x31, 0x32, 0x02, 0x03 };
- public static byte[] AESEncrypt(byte[] input)
- {
- SymmetricAlgorithm aes = Rijndael.Create();
- aes.IV = _iv;
- aes.Key = _key;
- using (MemoryStream ms = new MemoryStream())
- {
- CryptoStream cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write);
- cs.Write(input, 0, input.Length);
- cs.FlushFinalBlock();
- return ms.ToArray();
- }
- }
- public static byte[] AESDecrypt(byte[] input)
- {
- SymmetricAlgorithm aes = Rijndael.Create();
- aes.IV = _iv;
- aes.Key = _key;
- using (MemoryStream ms = new MemoryStream())
- {
- CryptoStream cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Write);
- cs.Write(input, 0, input.Length);
- cs.FlushFinalBlock();
- return ms.ToArray();
- }
- }
- }
- }
|