zoukankan      html  css  js  c++  java
  • byte数组的两种简单赋值操作

    第一种 直接操作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);

                   }

    }

  • 相关阅读:
    ES6中的let关键字,有什么用呢?
    ES6系列-什么是ES6?新手应该怎么理解
    css的变量教程,更强大的css
    尤雨溪在直播中讲到的Vue3.0 Beta的那些特性,快记笔记了
    前端基础进阶(七)-前端工程师最容易出错的问题-this关键字
    前端基础进阶(六)-大厂面试题问题:循环闭包与setTimeout
    JavaScript 中 this的指向
    What happens to our code? JavaScript 代码是怎样执行的
    Truthy and Falsy Values and Equality Operators
    iDisposable
  • 原文地址:https://www.cnblogs.com/smartsensor/p/3090571.html
Copyright © 2011-2022 走看看