本文整理汇总了C#中System.Byte.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Byte.Clone方法的具体用法?C# Byte.Clone怎么用?C# Byte.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Byte
的用法示例。
在下文中一共展示了Byte.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Pad
/// <summary>
/// Pads the bytes with zero byte padding scheme.
/// </summary>
public static Byte[] Pad(Byte[] bytes, Int32 size)
{
Byte[] c = (Byte[])bytes.Clone();
while (c.Length % size != 0)
{
Array.Resize(ref c, c.Length + 1);
c[c.Length - 1] = (Byte)0x00;
}
return c;
}
示例2: NFSAttributes
public NFSAttributes(int cdateTime, int adateTime, int mdateTime, NFSItemTypes type, NFSPermission mode, long size, Byte[] handle)
{
this._cdateTime = new System.DateTime(1970, 1, 1).AddSeconds(cdateTime);
this._adateTime = new System.DateTime(1970, 1, 1).AddSeconds(adateTime);
this._mdateTime = new System.DateTime(1970, 1, 1).AddSeconds(mdateTime);
this._type = type;
this._size = size;
this._mode = mode;
this._handle = (Byte[])handle.Clone();
}
示例3: Distort
public void Distort(Byte[] plainText, out Byte[] distortedText)
{
int length = plainText.Length;
distortedText = (Byte[])plainText.Clone();
UInt32[] posDistortionSeq = m_GenerateDistortionSequence(length);
for (int i = 0; i < length; ++i)
{
Utils.Swap(ref distortedText[i], ref distortedText[posDistortionSeq[i] % length]);
}
}
示例4: Unpad
/// <summary>
/// Unpads the bytes with zero byte padding scheme.
/// </summary>
public static Byte[] Unpad(Byte[] bytes)
{
Byte[] c = (Byte[])bytes.Clone();
Byte s = (Byte)c[c.Length - 1];
while (s == (Byte)0x00)
{
s = (Byte)c[c.Length - 2];
Array.Resize(ref c, c.Length - 1);
}
return c;
}
示例5: Pad
/// <summary>
/// Pads the bytes with PKCS#7 padding scheme.
/// </summary>
public static Byte[] Pad(Byte[] bytes, Int32 size)
{
Byte[] c = (Byte[])bytes.Clone();
Int32 s = size - c.Length % size;
for (Int32 i = 0; i < s; i++)
{
Array.Resize(ref c, c.Length + 1);
c[c.Length - 1] = (Byte)s;
}
return c;
}
示例6: Unpad
/// <summary>
/// Unpads the bytes with PKCS#7 padding scheme.
/// </summary>
public static Byte[] Unpad(Byte[] bytes)
{
Byte[] c = (Byte[])bytes.Clone();
Byte s = (Byte)c[c.Length - 1];
for (Int32 i = s; i > 0; i--)
{
Int32 v = c[c.Length - 1];
Array.Resize(ref c, c.Length - 1);
if (s != v)
{
String msg = String.Format(ERROR_VALUE, v, s);
throw new Exception(msg);
}
}
return c;
}
示例7: BytesToPrintableAscii
//*************************************************************************
// Method: BytesToPrintableAscii
//
/// <summary>
/// Converts an array of bytes to a printable ASCII string.
/// </summary>
///
/// <param name="abtBytes">
/// Array of bytes to convert. Can't be null.
/// </param>
///
/// <param name="cReplacementCharacter">
/// Character to replace non-printable characters with. Must have a value
/// less than or equal to 127.
/// </param>
///
/// <remarks>
/// This method replaces any bytes greater than 127 with <paramref
/// name="cReplacementCharacter" />, then replaces any non-printable ASCII
/// characters with the same replacement character.
/// </remarks>
//*************************************************************************
public static String BytesToPrintableAscii(
Byte [] abtBytes,
Char cReplacementCharacter
)
{
Debug.Assert(abtBytes != null);
Debug.Assert( (Int32)cReplacementCharacter < 128 );
// Make a copy of the byte array.
Byte [] abtClone = ( Byte [] )abtBytes.Clone();
// Replace any bytes > 127.
for (Int32 i = 0; i < abtClone.Length; i++)
if (abtClone[i] > 127)
abtClone[i] = (Byte)cReplacementCharacter;
// Use the ASCIIEncoding to get a string. This leaves all bytes
// between 0 and 127 unmodified.
String sString = Encoding.ASCII.GetString(abtClone);
// Replace the non-printable characters.
return ( ReplaceNonPrintableAsciiCharacters(
sString, cReplacementCharacter) );
}
示例8: Write
public override void Write(Byte[] buffer, Int32 offset, Int32 count)
{
_sslHandler.WriteBuffer(IoBuffer.Wrap((Byte[])buffer.Clone(), offset, count));
}
示例9: RemoveWord
private int RemoveWord(ref Byte[] bts, string templateWord, int stopByte)
{
int startByte = Encoding.ASCII.GetString(bts, 0, bts.Length).IndexOf(templateWord, 0, stopByte);
if (startByte < 0) return 0;
int wordLength = templateWord.Length;
var buffer = (byte[])bts.Clone();
Array.Clear(bts, 0, bts.Length);
Array.Copy(buffer, 0, bts, 0, startByte);
Array.Copy(buffer, startByte + wordLength, bts, startByte, _pakSize - wordLength - startByte);
return wordLength;
}
示例10: BadPacket
public Int32 MyCallback
(
UInt32 bufferLength,
IntPtr pBuffer,
IntPtr context
)
{
Byte[ ] packetBuffer = new Byte[ bufferLength ];
Marshal.Copy( pBuffer, packetBuffer, 0, ( Int32 ) bufferLength );
String errorMessage = null;
PacketData.PacketBase packet = null;
PacketData.PacketType type = PacketData.ParsePacket
(
packetBuffer,
out packet,
out errorMessage
);
SysLogger.WriteToLog = true;
PacketData.PacketWrapper envelope = null;
long elapsedSesionTime = ElapsedMilliseconds;
if ( packet == null || type == PacketData.PacketType.U_N_D_F_I_N_E_D || errorMessage != null )
{
BadPacket badPacket = new BadPacket( );
#pragma warning disable 420 // reference to a volatile field is valid for Interlocked call
badPacket.badPacketSequence = System.Threading.Interlocked.Increment( ref _commonBadIndex );
#pragma warning restore 420
badPacket.packetTime = DateTime.UtcNow;
badPacket.rawPacketData = packetBuffer.Clone( ) as byte[ ];
badPacket.errorMessage = errorMessage;
using ( MemoryStream data = new MemoryStream( 256 ) )
{
badPacket.WriteTo( data );
envelope = new PacketData.PacketWrapper( new PacketData.CommandPsuedoPacket( "BadPacket", data.ToArray( ) ), PacketData.PacketType.U_N_D_F_I_N_E_D );
}
envelope.IsPseudoPacket = true;
envelope.PacketNumber = badPacket.PacketSequence;
envelope.Timestamp = badPacket.packetTime;
envelope.ReaderIndex = ( int ) _theReaderID.Handle;
envelope.ReaderName = _theReaderID.Name;
envelope.CommandNumber = _processedInventoryIndex;
envelope.ElapsedTimeMs = elapsedSesionTime;
}
else
{
envelope = new PacketData.PacketWrapper
(
packet,
type,
packetBuffer,
_commonRequestIndex,
elapsedSesionTime,
( int ) this.ReaderHandle,
Name
);
Debug.Assert( envelope.PacketType == type );
}
if ( VirtualReaderQueue != null )
{
lock ( VirtualReaderQueue )
{
VirtualReaderQueue.Enqueue( envelope );
}
}
lock ( PacketQueue )
{
PacketQueue.Enqueue( envelope );
}
#pragma warning disable 420 // reference to a volatile field is valid for Interlocked call
int queueSize = Interlocked.Increment( ref _queueCount );
#pragma warning restore 420
_maxQueueSize = queueSize > _maxQueueSize ? queueSize : _maxQueueSize;
if (queueSize > MAX_QUEUE_SIZE)
{
int loopCount = 0;
while (queueSize > TARGET_QUEUE_SIZE && loopCount < 1000)
{
loopCount++;
QueueEvent.Set();
Thread.Sleep(QUEUE_SLEEP_MS);
queueSize = _queueCount;
}
// Write an informational entry to the event log.
SysLogger.LogMessage(String.Format("Queue Size = {0}\nMax Queue Size = {1}\nSleep Count = {2}\nPacket Count = {3}", queueSize, _maxQueueSize, loopCount, ProcessedPacketCount));
}
return FunctionController.GetActionRequest( ) != FunctionControl.RequestedAction.Abort ? 0 : 1;
//.........这里部分代码省略.........
示例11: adjustContrastByteLevel
/// <summary>
/// adjust the Contrast from input 'source' and output a Byte array
/// </summary>
public Byte[] adjustContrastByteLevel(int value, Byte[] source)
{
double r, g, b;
// if (value == m_currentContrast)
// return source;
Byte[] result = (Byte[])source.Clone();
double contrast = (double)Math.Pow((100 + value) / 100.0, 2);
for (int y = 0; y < m_imageHeight; y++)
{
for (int x = 0; x < m_imageWidth; x++)
{
r = source[4 * x + y * (4 * m_imageWidth) + 2] / 255.0;
g = source[4 * x + y * (4 * m_imageWidth) + 1] / 255.0;
b = source[4 * x + y * (4 * m_imageWidth) + 0] / 255.0;
//Blue
//Converts Blue value to a value between 0 and 1
//Centers that value over 0 (value will be between -.5 and .5)
b -= 0.5f;
//Adjust the value by contrast (value will be between -127.5 and 127.5)
//(Value will usually be between -1 and 1)
b *= contrast;
//Value will be between -127 and 128
b += 0.5f;
//Clamp value
if (b > 1)
b = 1;
else if (b < 0)
b = 0;
//Green
g -= 0.5f;
g *= contrast;
g += 0.5f;
if (g > 1)
g = 1;
else if (g < 0)
g = 0;
//Red
r -= 0.5f;
r *= contrast;
r += 0.5f;
if (r > 1)
r = 1;
else if (r < 0)
r = 0;
result[4 * x + y * (4 * m_imageWidth) + 2] = (byte)(r * 255);
result[4 * x + y * (4 * m_imageWidth) + 1] = (byte)(g * 255);
result[4 * x + y * (4 * m_imageWidth) + 0] = (byte)(b * 255);
}
}
m_currentContrast = value;
return result;
}
示例12: adjustBrightnessByteLevel
/// <summary>
/// adjust the Brightness from input 'source' and output a Byte array
/// </summary>
public Byte[] adjustBrightnessByteLevel(int value, Byte[] source)
{
// if (value == m_currentBrightness)
// return source;
double adjustment = (double)(value) / (100.0 * 3);
adjustment *= (double)255;
int r, g, b;
//Byte[] result = new Byte[source.Length];
Byte[] result = (Byte[]) source.Clone();
for (int y = 0; y < m_imageHeight; y++)
{
for (int x = 0; x < m_imageWidth; x++)
{
// int outputIndex = 4 * (ImageWidth - 1 - x) + 4 * (ImageHeight - 1 - y) * ImageWidth;
//int inputIndex = 4 * (x) + (y) * (4 * ImageWidth);
b = source[4 * x + y * (4 * m_imageWidth) + 0];
g = source[4 * x + y * (4 * m_imageWidth) + 1];
r = source[4 * x + y * (4 * m_imageWidth) + 2];
b += (int)adjustment;
g += (int)adjustment;
r += (int)adjustment;
if (value > 0) // lightening
{
if (r > 255)
r = 255;
if (g > 255)
g = 255;
if (b > 255)
b = 255;
}
else
{
if (r < 0)
r = 0;
if (g < 0)
g = 0;
if (b < 0)
b = 0;
}
result[4 * x + y * (4 * m_imageWidth) + 0] = (byte)b;
result[4 * x + y * (4 * m_imageWidth) + 1] = (byte)g;
result[4 * x + y * (4 * m_imageWidth) + 2] = (byte)r;
}
}
m_currentBrightness = value;
return result;
}
示例13: Password
/// <summary>
/// Создает экземпляр класса
/// </summary>
/// <param name="salt">Синхропосылка</param>
/// <param name="hash">Хэш пароля</param>
/// <param name="hashAlgorithm">Алгоритм хэширования паролей</param>
public Password(Byte[] salt, Byte[] hash, HashAlgorithm hashAlgorithm)
: this(hashAlgorithm)
{
_salt = (Byte[])salt.Clone();
_hash = (Byte[])hash.Clone();
}
示例14: CreateOwnerKey
////////////////////////////////////////////////////////////////////
// Create owner key
////////////////////////////////////////////////////////////////////
private Byte[] CreateOwnerKey(
Byte[] UserBinaryPassword,
Byte[] OwnerBinaryPassword
)
{
// create hash array for owner password
Byte[] OwnerHash = MD5.ComputeHash(OwnerBinaryPassword);
// loop 50 times creating hash of a hash
for(Int32 Index = 0; Index < 50; Index++) OwnerHash = MD5.ComputeHash(OwnerHash);
Byte[] ownerKey = (Byte[]) UserBinaryPassword.Clone();
Byte[] TempKey = new Byte[16];
for(Int32 Index = 0; Index < 20; Index++)
{
for(Int32 Tindex = 0; Tindex < 16 ; Tindex++) TempKey[Tindex] = (Byte)(OwnerHash[Tindex] ^ Index);
EncryptRC4(TempKey, ownerKey);
}
// return encryption key
return(ownerKey);
}
示例15: EncryptByteArray
////////////////////////////////////////////////////////////////////
// Encrypt byte array
////////////////////////////////////////////////////////////////////
internal Byte[] EncryptByteArray(
Int32 ObjectNumber,
Byte[] PlainText
)
{
// create encryption key
Byte[] EncryptionKey = CreateEncryptionKey(ObjectNumber);
Byte[] CipherText;
if(EncryptionType == EncryptionType.Aes128)
{
MemoryStream OutputStream = null;
CryptoStream CryptoStream = null;
// generate new initialization vector IV
AES.GenerateIV();
// create cipher text buffer including initialization vector
Int32 CipherTextLen = (PlainText.Length & 0x7ffffff0) + 16;
CipherText = new Byte[CipherTextLen + 16];
Array.Copy(AES.IV, 0, CipherText, 0, 16);
// set encryption key and key length
AES.Key = EncryptionKey;
// Create the streams used for encryption.
OutputStream = new MemoryStream();
CryptoStream = new CryptoStream(OutputStream, AES.CreateEncryptor(), CryptoStreamMode.Write);
// write plain text byte array
CryptoStream.Write(PlainText, 0, PlainText.Length);
// encrypt plain text to cipher text
CryptoStream.FlushFinalBlock();
// get the result
OutputStream.Seek(0, SeekOrigin.Begin);
OutputStream.Read(CipherText, 16, CipherTextLen);
// release resources
CryptoStream.Clear();
OutputStream.Close();
}
else
{
CipherText = (Byte[]) PlainText.Clone();
EncryptRC4(EncryptionKey, CipherText);
}
// return result
return(CipherText);
}