Transform() public method

Transforms the specified data in-place.
Thrown if is .
public Transform ( byte data ) : void
data byte The array to transform. This array will be directly modified.
return void
Ejemplo n.º 1
0
 /// <summary>
 /// Decrypts the given packet in-place.
 /// </summary>
 /// <remarks>
 /// The array will be modified directly.
 /// </remarks>
 /// <param name="packet">The data to decrypt.</param>
 public void Decrypt(byte[] packet)
 {
     lock (_decryptor)
     {
         _decryptor.Transform(packet);
         CustomCrypto.Decrypt(packet);
     }
 }
Ejemplo n.º 2
0
        public void Transform_Calls_TransformArraySegment_And_ShuffleIv()
        {
            var algorithm = new Mock <ICryptoAlgorithm>(MockBehavior.Loose);
            var initialIv = new byte[] { 0x12, 0x34, 0x56, 0x78 };
            var rollingIv = new RollingIv(algorithm.Object, initialIv, 0x1234);
            var data      = new byte[] { 0x12, 0x34 };

            rollingIv.Transform(data);

            algorithm.Verify(m => m.TransformArraySegment(AnyByteArray(), AnyByteArray(), 0, 2), Times.Once());
            algorithm.Verify(m => m.ShuffleIv(AnyByteArray()), Times.Once());
        }
Ejemplo n.º 3
0
        public void Transform_Calls_TransformArraySegment_And_ShuffleIv()
        {
            var algorithm = new Mock<ICryptoAlgorithm>(MockBehavior.Loose);
            var initialIv = new byte[] { 0x12, 0x34, 0x56, 0x78 };
            var rollingIv = new RollingIv(algorithm.Object, initialIv, 0x1234);
            var data = new byte[] { 0x12, 0x34 };

            rollingIv.Transform(data);

            algorithm.Verify(m => m.TransformArraySegment(AnyByteArray(), AnyByteArray(), 0, 2), Times.Once());
            algorithm.Verify(m => m.ShuffleIv(AnyByteArray()), Times.Once());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Encrypts a packet, constructs a header for it and packs them into a new array.
        /// </summary>
        /// <remarks>
        /// The array given as the <paramref name="packetData"/> parameter is transformed in-place.
        /// </remarks>
        /// <param name="packetData">The packet data to encrypt and pack.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="packetData"/> is <see langword="null"/>.
        /// </exception>
        /// <returns>an array with the encrypted packet and its header.</returns>
        public byte[] EncryptAndPack(byte[] packetData)
        {
            Guard.NotNull(() => packetData, packetData);

            int length  = packetData.Length;
            var rawData = new byte[length + 4];

            lock (_encryptor)
            {
                byte[] header = ConstructHeader(length);
                Buffer.BlockCopy(header, 0, rawData, 0, 4);

                CustomCrypto.Encrypt(packetData);
                _encryptor.Transform(packetData);
            }

            Buffer.BlockCopy(packetData, 0, rawData, 4, length);
            return(rawData);
        }