心澄欲遣

不践迹,亦不入于室

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

第一种 直接操作byte数组

private  void SetValue(byte[] byteArr)        

{

            byte[] LenK = new byte[4];            

    byte[] LenIV = new byte[4];

            Buffer.BlockCopy(byteArr,0,LenK,0,4);            

     Buffer.BlockCopy(byteArr, 4, LenIV, 0, 4);

            int lenK = BitConverter.ToInt32(LenK, 0);            

    int lenIV = BitConverter.ToInt32(LenIV, 0);

            byte[] KeyEncrypted = new byte[lenK];            

    byte[] IV = new byte[lenIV];

            Buffer.BlockCopy(byteArr, 8, KeyEncrypted, 0, lenK);            

    Buffer.BlockCopy(byteArr, 8 + lenK, IV, 0, lenIV);

            byte[] KeyDecrypted = rsa.Decrypt(KeyEncrypted, false);            

    byte[] IVDecrypted = rsa.Decrypt(IV, false);

}

第二种方法

 private void SetValue(byte[] byteArr)        

{            

using (Stream inFs = new MemoryStream(byteArr))            

{                

    byte[] LenK = new byte[4];                

    byte[] LenIV = new byte[4];                

    inFs.Seek(0, SeekOrigin.Begin);                

    inFs.Read(LenK, 0, 4);                

    inFs.Seek(4, SeekOrigin.Begin);                

    inFs.Read(LenIV, 0, 4);

           int lenK = BitConverter.ToInt32(LenK, 0);                

    int lenIV = BitConverter.ToInt32(LenIV, 0);

            byte[] KeyEncrypted = new byte[lenK];                

    byte[] IV = new byte[lenIV];

           inFs.Seek(8, SeekOrigin.Begin);                

    inFs.Read(KeyEncrypted, 0, lenK);                

    inFs.Seek(8 + lenK, SeekOrigin.Begin);                

    inFs.Read(IV, 0, lenIV);

               }

}

posted on 2013-05-21 13:22  心澄欲遣  阅读(6051)  评论(0编辑  收藏  举报
欢迎第myspace graphics个访客