《AES算法原理与应用》由会员分享,可在线阅读,更多相关《AES算法原理与应用(6页珍藏版)》请在金锄头文库上搜索。
1、ASE 算法原理与实现产生背景1、AES是美国国家标准技术研究所NIST旨在取代DES的新一代的加密标准。NIST 对AES候选算法的基本要求是:对称分组密码体制;密钥长度支持128 ,192 ,256 位;明文分组长度128 位; 算法应易于各种硬件和软件实现。2、1998年NIST开始AES第一轮征集、分析、测试,共产生了 15个候选算法。1999 年3月完成了第二轮AES的分析、测试。1999年8月NIST公布了五种算法 (MARS , RC6 ,Rijndael ,Serpent ,Twofish)成为候选算法。最后,Rijndael , 这个由比利时人设计的算法与其它候选算法在成为高
2、级加密标准 (AES) 的竞争 中取得成功,于2000年10月被NIST宣布成为取代DES的新一代的数据加密标准, 即 AES。3、Rijndael 作为新一代的数据加密标准汇聚了强安全性、高性能、高效率、易 用和灵活等优点。4、AES 设计有三个密钥长度:128 ,192 ,256 比特AES 加密/ 解密算法原理AES 算法属于分组密码算法, 它的输入分组、输出分组以及加/ 解密过程中的中 间分组都是128比特。(对称密码算法根据对明文消息加密方式的不同可分为两 大类,即分组密码和流密码。分组密码将消息分为固定长度的分组, 输出的密文分 组通常与输入的明文分组长度相同。)1、 AES 的加
3、密与解密框图如图所示/少忖竽很左鋼/ c 二 E 二乏二二 U 二二二二丘电前込匕文二(厂皿 典咔和沆斤屯II2S * 敕据 J/畔y严心:|/ 与扩展喀钥缎舁或疋算 c二二 $7二二 n u二E f達匸二 2亚汕衣二 777 二二 r4 h i Pn-nipIlKiiiF KJAddkrV4-Inirrv 4ih bjm14min r*i*LmiK =1; i )/ Nr根据密钥长度进行取值InvRound (State, InvMixColumn (ExpandedKey+Nb* i);/解密轮函数InvFinalRound (State, ExpandedKey); /解密最后一轮轮函数
4、解密轮函数:InvRound (State, RoundKey)InvShif tRow (Stat e);/逆 移位变换InvBy teSub (S tat e);/逆 字节替代变换AddRoundKey (State, RoundKey);/子 密钥加InvMixColumn (State); /逆列混合变换解密最后一轮轮函数:InvFinalRound (State, RoundKey)InvShif tRow (Stat e);/逆移位变换InvBy teSub (S tat e);/逆 字节替代变换 AddRoundKey (State, RoundKey);/逆列混合变换AES算法
5、应用举例控制台应用程序Program.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AES_DemoConAppclass Programstatic void Main(string args)/明文(以字节数组的形式表示)byte plainText = new byte 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
6、0xff;/存放加密后的密文(同样以字节数组形式表示)byte cipherText = null; /new byte16;/存放解密后的明文byte decipheredText = null;/new byte16;/加密的密钥byte keyBytes = new byte 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17;Console.WriteLine
7、(nAdvanced Encryption Standard Demo in .NET); Console.WriteLine(nThe plaintext is: );DisplayAsBytes(plainText);CryptoHelper helper2 = new CryptoHelper(Rijndael, 1234567812345678); helper2.Cipher(plainText, ref cipherText);Console.WriteLine(nThe resulting ciphertext is: ); DisplayAsBytes(cipherText);
8、helper2.InvCipher(cipherText, ref decipheredText);Console.WriteLine(nAfter deciphering the ciphertext, the result is: ); DisplayAsBytes(decipheredText);Console.WriteLine(nDone);Console.ReadLine();static void DisplayAsBytes(byte bytes)for (int i = 0; i 0 & i % 16 = 0) Console.Write(n);Console.WriteLi
9、ne(); / DisplayAsBytes()运行结果Advanced Encryption Standard Beno in -NETThe plaintext is:00 11 22 33 44 55 &6 ? 88 99 aa hh cc dd ee FfThe resulting cipliertext is:9a e8 d &2 b3 40 28 8a &e 7b hf F0 ba 54 d6 ?4 hf 2e el de &S F6 9S 00 b4 ca a? 0c de 41 6dEf tei* deciphei*incF the ciphertext., the result is: Q 11 22 33 44 55 6& 77 88 99 嗣 bb cc dd ee ffBone