Exemplo n.º 1
0
 public void Init()
 {
     this.hexConverter = new HexConverter();
     this.symCryptor = new SymCryptor("AES");
     this.paddingHelper = new Pkcs7PaddingHelper();
     this.byteWorker = new ByteWorker();
     // aes-128-cbc
     //byte[] key = {145,12,32,245,98,132,98,214,6,77,131,44,221,3,9,50};
     //KEY(128|192|256,128bit):910C20F5628462D6064D832CDD030932
     // AES-192-CBC
     //***************************************
     string keyString = "0123456789abcdef";//AES用的加解密金鑰字串
     string hexKeyString = this.hexConverter.Str2Hex(keyString);//AES用的加解密金鑰轉hex
     Debug.WriteLine("Hex Key String:" + hexKeyString);
     //***************************************
     byte[] key = this.hexConverter.Hex2Bytes //AES用的加解密金鑰轉Byte Array(固定長度: 16 bytes)
     (
         // "00112233445566778899AABBCCDDEEFF0102030405060708"
        //"3FE9489CC954E7DA1B4806A8133B81EB"
        hexKeyString//16 bytes
     );
     //
     //byte[] iv = {15,122,132,5,93,198,44,31,9,39,241,49,250,188,80,7};
     //IV(128bit):0F7A84055DC62C1F0927F131FABC5007
     //IV: ALL ZERO
     //byte[] iv = new byte[16];
     //for (int i = 0; i < iv.Length; i++)
     //{
     //    iv[i] = 0;
     //}
     //
     this.symCryptor.SetIV(SymCryptor.ConstZero);
     this.symCryptor.SetKey(key);
     //log.Debug( "KEY:" + this.hexConverter.Bytes2Hex( key ) );
     //log.Debug( "IV:" + this.hexConverter.Bytes2Hex( iv ) );
 }
Exemplo n.º 2
0
 public void InitContext()
 {
     this.hexConverter = new HexConverter();
     this.pkcs7PaddingHelper = new Pkcs7PaddingHelper();
     this.byteWorker = new ByteWorker();
 }