Encrypt() public static method

public static Encrypt ( byte masterKey, ArraySegment plaintext, ArraySegment salt = null, uint counter = 1 ) : byte[]
masterKey byte
plaintext ArraySegment
salt ArraySegment
counter uint
return byte[]
Ejemplo n.º 1
0
		public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
		{
			int partialBlockSize = inputCount % EtM_Transform_Constants.INPUT_BLOCK_SIZE;
			int fullBlockSize = inputCount - partialBlockSize;

			if (partialBlockSize != 0)
				throw new Exception("inputCount must be a multiple of input block size (" + EtM_Transform_Constants.INPUT_BLOCK_SIZE.ToString() + ").");

			int i = 0, j = 0;
			if (fullBlockSize > 0)
			{
				for (; i < fullBlockSize; i += EtM_Transform_Constants.INPUT_BLOCK_SIZE, j += EtM_Transform_Constants.OUTPUT_BLOCK_SIZE)
				{
					EtM_CTR.Encrypt(
						masterKey: this.key,
						plaintext: new ArraySegment<byte>(inputBuffer, inputOffset + i, EtM_Transform_Constants.INPUT_BLOCK_SIZE),
						output: outputBuffer,
						outputOffset: outputOffset + j,
						salt: this.salt,
						counter: this.currentChunkNumber);

					if (this.currentChunkNumber == EtM_Transform_Constants.INITIAL_CHUNK_NUMBER)
					{
						EtM_EncryptTransform.PrependSaltWith1stBlockContext(ref this.salt, outputBuffer, outputOffset);
					}

					checked { ++this.currentChunkNumber; }
				}
			}
			return j;
		}// TransformBlock()
Ejemplo n.º 2
0
		}// TransformBlock()

		public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
		{
			if (this.key == null) return null; // key would be null if this instance has already been disposed
			if (inputCount >= EtM_Transform_Constants.INPUT_BLOCK_SIZE)
				throw new Exception("Final input block size must be smaller than " + EtM_Transform_Constants.INPUT_BLOCK_SIZE.ToString() + ".");

			byte[] outputBuffer = new byte[EtM_Transform_Constants.ETM_CTR_OVERHEAD + inputCount];

			EtM_CTR.Encrypt(
				masterKey: this.key,
				plaintext: new ArraySegment<byte>(inputBuffer, inputOffset, inputCount),
				output: outputBuffer,
				outputOffset: 0,
				salt: this.salt,
				counter: this.currentChunkNumber);

			this.Dispose();
			return outputBuffer;
		}// TransformFinalBlock()
Ejemplo n.º 3
0
		public static byte[] Encrypt(byte[] masterKey, ArraySegment<byte> plaintext, ArraySegment<byte>? salt = null)
		{
			return EtM_CTR.Encrypt(masterKey, plaintext, salt);
		}
Ejemplo n.º 4
0
		}// Encrypt()

		public static byte[] Encrypt(byte[] masterKey, ArraySegment<byte> plaintext, ArraySegment<byte>? salt = null, uint counter = 1)
		{
			byte[] buffer = new byte[CONTEXT_BUFFER_LENGTH + plaintext.Count + MAC_LENGTH];
			EtM_CTR.Encrypt(masterKey: masterKey, plaintext: plaintext, output: buffer, outputOffset: 0, salt: salt, counter: counter);
			return buffer;
		}// Encrypt()