本文整理汇总了C#中System.Byte.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# Byte.CopyTo方法的具体用法?C# Byte.CopyTo怎么用?C# Byte.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Byte
的用法示例。
在下文中一共展示了Byte.CopyTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BTDeviceInfo
public BTDeviceInfo(Byte[] bt_addr)
{
device_name = string.Empty;
address = new byte[6];
bt_addr.CopyTo(address, 0);
clockOffset = 0;
classOfDevice = 0;
pageScanRepetitionMode = 0;
rssi = 0;
state = Status.Empty;
}
示例2: CreateSaltedPassword
private static Byte[] CreateSaltedPassword(Byte[] saltValue, Byte[] unsaltedPassword)
{
var rawSalted = new Byte[unsaltedPassword.Length + saltValue.Length];
unsaltedPassword.CopyTo(rawSalted, 0);
saltValue.CopyTo(rawSalted, unsaltedPassword.Length);
var sha1 = SHA1.Create();
var saltedPassword = sha1.ComputeHash(rawSalted);
var dbPassword = new Byte[saltedPassword.Length + saltValue.Length];
saltedPassword.CopyTo(dbPassword, 0);
saltValue.CopyTo(dbPassword, saltedPassword.Length);
return dbPassword;
}
示例3: SetFieldValue
/// <summary>
/// 设置表单文件数据
/// </summary>
/// <param name="fieldName">字段名</param>
/// <param name="filename">字段值</param>
/// <param name="contentType">内容内型</param>
/// <param name="fileBytes">文件字节流</param>
/// <returns></returns>
public void SetFieldValue(String fieldName, String filename, String contentType, Byte[] fileBytes)
{
string end = "\r\n";
string httpRow = "--" + boundary + "\r\nContent-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n";
string httpRowData = String.Format(httpRow, fieldName, filename, contentType);
byte[] headerBytes = encoding.GetBytes(httpRowData);
byte[] endBytes = encoding.GetBytes(end);
byte[] fileDataBytes = new byte[headerBytes.Length + fileBytes.Length + endBytes.Length];
headerBytes.CopyTo(fileDataBytes, 0);
fileBytes.CopyTo(fileDataBytes, headerBytes.Length);
endBytes.CopyTo(fileDataBytes, headerBytes.Length + fileBytes.Length);
bytesArray.Add(fileDataBytes);
}
示例4: ConvertAndWrite
void ConvertAndWrite(float[] dataSource)
{
Int16[] intData = new Int16[dataSource.Length];
//converting in 2 steps : float[] to Int16[], //then Int16[] to Byte[]
Byte[] bytesData = new Byte[(int)dataSource.Length * 2];
//bytesData array is twice the size of
//dataSource array because a float converted in Int16 is 2 bytes.
int rescaleFactor = 32767; //to convert float to Int16
for (int i = 0; i < dataSource.Length; i++)
{
intData[i] = (Int16)(dataSource[i] * rescaleFactor);
Byte[] byteArr = new Byte[2];
byteArr = BitConverter.GetBytes(intData[i]);
byteArr.CopyTo(bytesData, i * 2);
}
fileStream.Write(bytesData, 0, bytesData.Length);
}
示例5: sendMessage
public void sendMessage(Byte[] messageData, OpenCOVERPlugin.COVER.MessageTypes msgType)
{
int len = messageData.Length + (4 * 4);
Byte[] data = new Byte[len];
ByteSwap.swapTo((uint)msgType, data, 2 * 4);
ByteSwap.swapTo((uint)messageData.Length, data, 3 * 4);
messageData.CopyTo(data, 4 * 4);
toCOVER.GetStream().Write(data, 0, len);
}
示例6: ConvertOggToRAW
/**
* Reads an OGG audio clip and converts it to *.raw file
* */
public static void ConvertOggToRAW(String srcoggfile, String dstrawfile)
{
srcoggfile = Path.GetFullPath(srcoggfile);
dstrawfile = Path.GetFullPath(dstrawfile);
Debug.Log("[CSLMusic] Convert " + srcoggfile + " to " + dstrawfile);
try
{
using (var vorbis = new NVorbis.VorbisReader(srcoggfile))
{
using (var fileStream = new FileStream(dstrawfile, FileMode.Create))
{
//NVorbis data
int channels = vorbis.Channels;
int sampleRate = vorbis.SampleRate;
var duration = vorbis.TotalTime;
if(channels != 2 || sampleRate != 44100)
{
Debug.LogError("[CSLMusic] Error: Input file " + srcoggfile + " must have 2 channels and 44100Hz sample rate!");
//Add to list
//ConversionManager.Info_NonConvertedFiles.Add(srcoggfile);
return;
}
var buffer = new float[16384];
int count;
//From SavWav
Int16[] intData = new Int16[buffer.Length];
//converting in 2 float[] steps to Int16[], //then Int16[] to Byte[]
Byte[] bytesData = new Byte[buffer.Length * 2];
//bytesData array is twice the size of
//dataSource array because a float converted in Int16 is 2 bytes.
int rescaleFactor = 32767; //to convert float to Int16
while ((count = vorbis.ReadSamples(buffer, 0, buffer.Length)) > 0)
{
// Do stuff with the samples returned...
// Sample value range is -0.99999994f to 0.99999994f
// Samples are interleaved (chan0, chan1, chan0, chan1, etc.)
for (int i = 0; i<buffer.Length; i++)
{
intData[i] = (short)(buffer[i] * rescaleFactor);
Byte[] byteArr = new Byte[2];
byteArr = BitConverter.GetBytes(intData[i]);
byteArr.CopyTo(bytesData, i * 2);
}
fileStream.Write(bytesData, 0, bytesData.Length);
}
}
}
}
catch (InvalidDataException ex)
{
Debug.LogError("... ERROR: Could not read file! " + ex.Message);
//Add to list
//CSLMusicModSettings.Info_NonConvertedFiles.Add(srcoggfile);
return;
}
Debug.Log("... done.");
}
示例7: ProcessBackendResponses_Ver_3
protected virtual void ProcessBackendResponses_Ver_3( NpgsqlConnector context )
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "ProcessBackendResponses");
Stream stream = context.Stream;
NpgsqlMediator mediator = context.Mediator;
// Often used buffers
Byte[] inputBuffer = new Byte[ 4 ];
String Str;
Boolean readyForQuery = false;
byte[] asciiRowBytes = new byte[300];
char[] asciiRowChars = new char[300];
while (!readyForQuery)
{
// Check the first Byte of response.
Int32 message = stream.ReadByte();
switch ( message )
{
case NpgsqlMessageTypes_Ver_3.ErrorResponse :
{
NpgsqlError error = new NpgsqlError(context.BackendProtocolVersion);
error.ReadFromStream(stream, context.Encoding);
error.ErrorSql = mediator.SqlSent;
mediator.Errors.Add(error);
NpgsqlEventLog.LogMsg(resman, "Log_ErrorResponse", LogLevel.Debug, error.Message);
}
// Return imediately if it is in the startup state or connected state as
// there is no more messages to consume.
// Possible error in the NpgsqlStartupState:
// Invalid password.
// Possible error in the NpgsqlConnectedState:
// No pg_hba.conf configured.
if (! mediator.RequireReadyForQuery)
{
return;
}
break;
case NpgsqlMessageTypes_Ver_3.AuthenticationRequest :
NpgsqlEventLog.LogMsg(resman, "Log_ProtocolMessage", LogLevel.Debug, "AuthenticationRequest");
// Eat length
PGUtil.ReadInt32(stream, inputBuffer);
{
Int32 authType = PGUtil.ReadInt32(stream, inputBuffer);
if ( authType == NpgsqlMessageTypes_Ver_3.AuthenticationOk )
{
NpgsqlEventLog.LogMsg(resman, "Log_AuthenticationOK", LogLevel.Debug);
break;
}
if ( authType == NpgsqlMessageTypes_Ver_3.AuthenticationClearTextPassword )
{
NpgsqlEventLog.LogMsg(resman, "Log_AuthenticationClearTextRequest", LogLevel.Debug);
// Send the PasswordPacket.
ChangeState( context, NpgsqlStartupState.Instance );
context.Authenticate(context.Password);
break;
}
if ( authType == NpgsqlMessageTypes_Ver_3.AuthenticationMD5Password )
{
NpgsqlEventLog.LogMsg(resman, "Log_AuthenticationMD5Request", LogLevel.Debug);
// Now do the "MD5-Thing"
// for this the Password has to be:
// 1. md5-hashed with the username as salt
// 2. md5-hashed again with the salt we get from the backend
MD5 md5 = MD5.Create();
// 1.
byte[] passwd = context.Encoding.GetBytes(context.Password);
byte[] saltUserName = context.Encoding.GetBytes(context.UserName);
byte[] crypt_buf = new byte[passwd.Length + saltUserName.Length];
passwd.CopyTo(crypt_buf, 0);
saltUserName.CopyTo(crypt_buf, passwd.Length);
//.........这里部分代码省略.........
示例8: GenerateLoadModule
public static Byte[] GenerateLoadModule(LoadModule loadMod, Byte[] loadData)
{
Byte[] outputData, sigData;
Byte[] outputDataSigOrder, encOutputData;
Int32 sigSize = 0;
if (loadMod.SecureType == AisSecureType.CUSTOM)
{
sigSize = (loadMod.rsaObject.KeySize >> 3);
}
else if (loadMod.SecureType == AisSecureType.GENERIC)
{
sigSize = 32;
}
if ((loadData.Length % 16) != 0)
{
Int32 len = ((loadData.Length + 15) / 16) * 16;
Byte[] temp = new Byte[len];
loadData.CopyTo(temp,0);
loadData = temp;
}
outputData = new Byte[loadData.Length + 16 + sigSize];
// Fill with random data
(new Random()).NextBytes(outputData);
// Insert load module header data
BitConverter.GetBytes((UInt32)loadMod.MagicNum).CopyTo(outputData, 0 );
BitConverter.GetBytes((UInt32)outputData.Length).CopyTo(outputData, 4 );
// FIXME - use random data in practice
BitConverter.GetBytes((UInt32)0x00000000).CopyTo(outputData, 8 );
BitConverter.GetBytes((UInt32)0x00000000).CopyTo(outputData, 12 );
// Insert load module payload data at offset 16
loadData.CopyTo(outputData, 16);
// Create copy of load module in output/signature order
outputDataSigOrder = new Byte[outputData.Length - sigSize];
Array.Copy(outputData, 0 , outputDataSigOrder, loadData.Length, 16);
loadData.CopyTo(outputDataSigOrder, 0);
// Encrypt the data (load header first, then payload)
if (loadMod.encryptData)
{
encOutputData = AesManagedUtil.AesCBCEncrypt(outputData, loadMod.customerEncryptionKey, loadMod.CEKInitialValue);
Array.Copy(encOutputData, 0 , outputData, loadData.Length, 16);
Array.Copy(encOutputData, 16, outputData, 0, loadData.Length);
}
else
{
outputDataSigOrder.CopyTo(outputData, 0);
}
// Generate and Insert Signature
sigData = GenerateSecureSignature(loadMod, outputDataSigOrder);
// Append signature to the end of output data
sigData.CopyTo(outputData, (loadData.Length + 16));
return outputData;
}
示例9: DataArrived
/// <summary>
/// Функция записи звука
/// </summary>
/// <param name="data">Информация</param>
/// <param name="size">Размер информации</param>
private void DataArrived(Byte[] data, int size)
{
if (m_RecBuffer == null || m_RecBuffer.Length < size)
m_RecBuffer = new byte[size];
data.CopyTo(m_RecBuffer, 0);
m_Fifo.Write(m_RecBuffer, 0, m_RecBuffer.Length);
}
示例10: InsertAISSetDelegateKey
public virtual retType InsertAISSetDelegateKey(String rsaKeyFileName, String keyString)
{
RSACryptoServiceProvider localRsaObject;
Byte[] localEncryptionKey = null;
Byte[] localEKInitialValue = null;
if ( this.SecureType != AisSecureType.CUSTOM)
{
Console.WriteLine("WARNING: Delegate Key commands only apply to Custom Secure devices. AIS section ignored.");
return retType.SUCCESS;
}
Debug.DebugMSG("Inserting AIS Set Delegate Key command.");
localRsaObject = RSAKey.LoadFromFile(rsaKeyFileName);
if (localRsaObject == null)
{
Console.WriteLine("SetDelegateKey: RSA key loading failed!");
return retType.FAIL;
}
// Update the hash algo string if RSA key size is 2048 bits
if (localRsaObject.KeySize != this.rsaObject.KeySize)
{
Console.WriteLine("ERROR: SetDelegateKey: Delegate key size cannot differ from current key size.");
return retType.FAIL;
}
// Parse Encryption Key Value
localEncryptionKey = new Byte[16];
localEKInitialValue = new Byte[16];
if (keyString.Length != 32)
{
Console.WriteLine("SetDelegateKey: AES Encryption Key is wrong length!");
return retType.FAIL;
}
for (int j=0; j<keyString.Length; j+=2)
{
localEncryptionKey[(j>>1)] = Convert.ToByte(keyString.Substring(j,2),16);
}
// Generate IV as encrypted version of AES Key
using (MemoryStream ms = new MemoryStream(localEKInitialValue))
{
Aes myAES = new AesManaged();
myAES.KeySize = 128;
myAES.Mode = CipherMode.ECB;
myAES.Padding = PaddingMode.None;
ICryptoTransform encryptor = myAES.CreateEncryptor(localEncryptionKey, new Byte[16]);
CryptoStream cs = new CryptoStream(ms,encryptor,CryptoStreamMode.Write);
cs.Write(localEncryptionKey,0,localEncryptionKey.Length);
}
// Create Delegate Key Certificate Format
//Key cert: 304 bytes
// decryptionKey: 16 byte (128 bits) AES key
// rsaPublicKey: 8 bytes + 128/256 for modulus data (actual modulus data may only be 128 bytes for RSA1024)
// keyExponent: 4 bytes
// keyPad: 2 bytes
// modLength: 2 bytes
// modData: 128 or 256 bytes
// keyFlags: 8 bytes
// infoData: 16 bytes
// loadModMagic: 4 bytes
// loadModSize: 4 bytes
// randomSeed: 8 bytes
Byte[] delegateKeyData = new Byte[48 + (localRsaObject.KeySize >> 3)];
// Fill with random data
(new Random()).NextBytes(delegateKeyData);
// Insert load module header data
BitConverter.GetBytes((UInt32)SecureLoadMagic.CERT_MAGIC).CopyTo(delegateKeyData, 0 );
BitConverter.GetBytes((UInt32)delegateKeyData.Length).CopyTo(delegateKeyData, 4 );
// Insert decryptionKey at offset 16
localEncryptionKey.CopyTo(delegateKeyData, 16);
// Insert rsaPublicKey at offset 32
RSAKey.CreateCustomSecureKeyVerifyStruct(localRsaObject).CopyTo(delegateKeyData, 32);
// Insert flags data
BitConverter.GetBytes((UInt32)0x00000000).CopyTo(delegateKeyData, 40 + (localRsaObject.KeySize >> 3) );
BitConverter.GetBytes((UInt32)0x00000000).CopyTo(delegateKeyData, 44 + (localRsaObject.KeySize >> 3) );
#if (DEBUG)
FileIO.SetFileData("delegatdata.bin",delegateKeyData, true);
#endif
Byte[] delegateKeyDataSigOrder = new Byte[48 + (localRsaObject.KeySize >> 3)];
Array.Copy(delegateKeyData, 0 , delegateKeyDataSigOrder, 32 + (localRsaObject.KeySize >> 3), 16);
Array.Copy(delegateKeyData, 16, delegateKeyDataSigOrder, 0, 32 + (localRsaObject.KeySize >> 3));
#if (DEBUG)
FileIO.SetFileData("delegatdata_sigorder.bin",delegateKeyDataSigOrder, true);
#endif
// Insert AIS command and key data into signature data stream
if ( this.SecureType == AisSecureType.CUSTOM)
//.........这里部分代码省略.........
示例11: AISSectionLoad
private static retType AISSectionLoad( AISGen devAISGen, ObjectFile file, ObjectSection section)
{
Byte[] secData = file.secRead(section);
Byte[] srcCRCData = new Byte[section.size + 8];
Debug.DebugMSG("AISSectionLoad for section " + section.name + " from file " + file.FileName + ".");
// If we are doing section-by-section CRC, then zero out the CRC value
if (devAISGen.aisCRCType == AisCRCCheckType.SECTION_CRC)
{
devAISGen.devCRC.ResetCRC();
}
// Add section load to the output
devAISGen.InsertAISSectionLoad((UInt32) section.loadAddr, (UInt32) section.size, secData);
// Copy bytes to CRC byte array for future CRC calculation
if (devAISGen.aisCRCType != AisCRCCheckType.NO_CRC)
{
if (devAISGen.devEndian != devAISGen.devAISEndian)
{
Endian.swapEndian(BitConverter.GetBytes(section.loadAddr)).CopyTo(srcCRCData, 0);
Endian.swapEndian(BitConverter.GetBytes(section.size)).CopyTo(srcCRCData, 4);
}
else
{
BitConverter.GetBytes(section.loadAddr).CopyTo(srcCRCData, 0);
BitConverter.GetBytes(section.size).CopyTo(srcCRCData, 4);
}
}
// Now write contents to CRC array
for (UInt32 k = 0; k < section.size; k+=4)
{
// Copy bytes to array for future CRC calculation
if (devAISGen.aisCRCType != AisCRCCheckType.NO_CRC)
{
Byte[] temp = new Byte[4];
Array.Copy(secData,k,temp,0,4);
if (devAISGen.devEndian != devAISGen.devAISEndian)
{
Endian.swapEndian(temp).CopyTo(srcCRCData, (8 + k));
}
else
{
temp.CopyTo(srcCRCData, (8 + k));
}
}
}
// Add this section's memory range, checking for overlap
AddMemoryRange(devAISGen, (UInt32) section.loadAddr, (UInt32) (section.loadAddr+section.size-1));
// Perform CRC calculation of the section's contents
if (devAISGen.aisCRCType != AisCRCCheckType.NO_CRC)
{
devAISGen.devCRC.CalculateCRC(srcCRCData);
if (devAISGen.aisCRCType == AisCRCCheckType.SECTION_CRC)
{
// Write CRC request command, value, and jump value to temp AIS file
devAISGen.InsertAISRequestCRC(((Int32)(-1) * (Int32)(section.size + 12 + 12)));
}
}
return retType.SUCCESS;
}
示例12: modbusEncode
/// <summary>
/// Encodes data in modbus format, so we can use write multiple registers
/// </summary>
/// <param name="data">Data encoded as <see cref="byte"/></param>
/// <returns>Data encoded as big endian <see cref="UInt16"/></returns>
public static UInt16[] modbusEncode(Byte[] data)
{
Byte[] newData = new Byte[data.Length + 1];
data.CopyTo(newData,0);
newData[newData.Length-1] = 0;
UInt16[] result = new UInt16[data.Length / 2+1];
for (int x = 0, y = 0; x < data.Length; x += 2, y++)
{
result[y] = BPModbusHelper.ReverseBytes(BitConverter.ToUInt16(newData, x));
}
return result;
}
示例13: ReadMessages
private void ReadMessages(Object sender, DoWorkEventArgs ev)
{
while (true)
{
try
{
Byte[] buffer = new Byte[READ_BUFFER_SIZE];
Byte[] bufferMsg = new Byte[READ_MESSAGE_SIZE];
byte[] bufferMsgSize = new byte[4];
int sum = 0;
int n = 0;
// Reads n bytes to buffer
n = peerStream.Read(buffer, 0, READ_BUFFER_SIZE);
//InfoMessage("READ - Bytes read = " + n);
// Retrieves message length from bytes 1 to 4
for (int i = 0; i < 4; i++) bufferMsgSize[i] = buffer[i + 1];
if (BitConverter.IsLittleEndian)
Array.Reverse(bufferMsgSize);
int messagelength = BitConverter.ToInt32(bufferMsgSize, 0);
// Copies temporary buffer to message buffer
buffer.CopyTo(bufferMsg, sum); sum += n;
// Sees if the message was all read in first read(...)
// If not, continue reading till message is all read
while (sum < messagelength)
{
buffer = new Byte[READ_BUFFER_SIZE];
n = peerStream.Read(buffer, 0, READ_BUFFER_SIZE);
//InfoMessage("READ - Bytes read = " + n);
buffer.CopyTo(bufferMsg, sum); sum += n;
}
InfoMessage("Read received!");
// Parse message
ReadParser(bufferMsg, sum);
}
catch (ObjectDisposedException ode)
{
InfoMessage("Stream was closed (read)");
break;
}
catch (Exception e)
{
ErrorMessage("Connection was closed hard (read). (ERR: "+e.Message+")");
break;
}
}
}
示例14: CopyData
private void CopyData(Byte[] source, Byte[] dest)
{
if (source.Length > dest.Length)
{
throw new ArgumentException(String.Format("Values must be no more than {0} bytes.", dest.Length), "value");
}
source.CopyTo(dest, 0);
}
示例15: readNetStreamInput
private async Task<byte[]> readNetStreamInput()
{
byte[] input = new byte[4096];
byte[] data;
int length;
length = await stream.ReadAsync(input, 0, input.Length);
if (client.Available != 0)
{
Byte[] nextBytes = new Byte[client.Available];
length += await stream.ReadAsync(nextBytes, 0, nextBytes.Length);
data = new byte[length];
input.CopyTo(data, 0);
nextBytes.CopyTo(data, input.Length);
}
else
{
data = new byte[length];
Array.Copy(input, data, length);
}
return data;
}