byte数组的两种简单赋值操作
2013-05-21 13:22
351 查看
第一种 直接操作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);
}
}
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);
}
}
相关文章推荐
- 操作数组的流 ByteArrayInputStream 和 ByteArrayOutputStream的简单介绍
- Flex与.NET互操作(十五):使用FluorineFx中的字节数组(ByteArray)实现图片上传
- 关于数组的一些简单操作
- C#四舍五入操作两种简单方法
- php简单数组操作,注意array_values()是重构数组
- 整型数组左移或右移位简单操作
- [Java 11] ArraysDemo 数组简单的排序,填充操作
- java中byte数组与int类型的转换(两种方式
- 关于在C#中数组(byte[])复制的两种方式。字节偏移复制与安全复制
- 两种将int类型的数据转换成byte数组,以及反向转换的代码
- js的数组简单操作(方法)
- 简单的数组循环操作
- 指针操作数组的两种方式
- 例子程序2:使用内存操作函数memset()给数组赋值
- objective c中的数组和简单操作(四)
- byte数组之间的赋值,byte和TCHAR数组的赋值
- javascript数组赋值操作
- js 数组赋值操作,修改数组元素的值
- C#: Json数组的 简单解析操作
- [Java 11] ArraysDemo 数组简单的排序,填充操作