软件注册码(算法二Rijndael)
1 /// <summary> 2 /// Rijndael算法 3 /// </summary> 4 public class RijndaelCrypto : ICrypto 5 { 6 /// <summary> 7 /// Key值 8 /// </summary> 9 private byte[] _key; 10 /// <summary> 11 /// IV向量 12 /// </summary> 13 private byte[] _iv = new byte[] { 107, 22, 226, 145, 208, 243, 46, 41 }; 14 public RijndaelCrypto(byte[] key) 15 { 16 this._key = key; 17 } 18 /// <summary> 19 /// 加密 20 /// </summary> 21 /// <param name="bytes"></param> 22 /// <returns></returns> 23 public byte[] Encrypt(byte[] bytes) 24 { 25 RijndaelManaged rm = this.GetProvider(); 26 ICryptoTransform it = rm.CreateEncryptor(rm.Key, rm.IV); 27 return it.TransformFinalBlock(bytes, 0, bytes.Length); 28 } 29 /// <summary> 30 /// 解密 31 /// </summary> 32 /// <param name="bytes"></param> 33 /// <returns></returns> 34 public byte[] Decrypt(byte[] bytes) 35 { 36 RijndaelManaged rm = this.GetProvider(); 37 ICryptoTransform it = rm.CreateDecryptor(rm.Key, rm.IV); 38 return it.TransformFinalBlock(bytes, 0, bytes.Length); 39 } 40 private RijndaelManaged GetProvider() 41 { 42 RijndaelManaged rm = new RijndaelManaged(); 43 rm.Key = this._key; 44 rm.IV = this._iv; 45 return rm; 46 } 47 }