private byte[] XorKeySizePadding(BigInteger cipheredAgainPreviousBlock, BigInteger block) { byte[] xorResult = BigIntegerExtensions.UnsignedToBytes(cipheredAgainPreviousBlock ^ block); int keySize = rsa.ExportParameters().Modulus.Length; return(BlockCipherSupport.PadWithZeros(xorResult, keySize)); }
public byte[] Cipher(byte[] data) { byte[] dataToDivide = BlockCipherSupport.AddPadding(data, BlockSize); List <byte[]> blocks = BlockCipherSupport.DivideIntoBlocks(dataToDivide, BlockSize); List <byte[]> cipheredBlocks = CipherBlocks(blocks); return(BlockCipherSupport.ConcatenateBlocks(cipheredBlocks)); }
public List <Chunk> DecipherWithoutFiltering(List <Chunk> chunks) { byte[] decompressedBytes = BlockCipherSupport.DecompressIDATs(chunks); byte[] decipheredBytes = blockCipher.Decipher(decompressedBytes); List <Chunk> resultIdats = BlockCipherSupport.CompressIDATs(decipheredBytes); List <Chunk> resultChunks = BlockCipherSupport.SwapIDATs(chunks, resultIdats); return(resultChunks); }
public byte[] Decipher(byte[] data) { RSAParameters parameters = rsa.ExportParameters(); int keySize = parameters.Modulus.Length; List <byte[]> blocks = BlockCipherSupport.DivideIntoBlocks(data, keySize); List <byte[]> decipheredBlocks = DecipherBlocks(blocks); return(BlockCipherSupport.RemovePadding(BlockCipherSupport.ConcatenateBlocks(decipheredBlocks))); }
private void DecipherBlocks(List <byte[]> blocks) { for (int i = 0; i < blocks.Count; i++) { BigInteger nonceCounterXor = InitializationVector ^ new BigInteger(i); byte[] nonceCounterXorBytes = rsa.Encrypt(BigIntegerExtensions.UnsignedToBytes(nonceCounterXor)); nonceCounterXor = BigIntegerExtensions.UnsignedFromBytes(nonceCounterXorBytes); BigInteger block = BigIntegerExtensions.UnsignedFromBytes(blocks[i]); block ^= nonceCounterXor; blocks[i] = BlockCipherSupport.PadWithZeros(BigIntegerExtensions.UnsignedToBytes(block), BlockSize); } }
public byte[] Cipher(byte[] data) { byte[] dataToDivide = BlockCipherSupport.AddPadding(data, BlockSize); List <byte[]> blocks = BlockCipherSupport.DivideIntoBlocks(dataToDivide, BlockSize); for (int i = 0; i < blocks.Count; i++) { blocks[i] = rsa.Encrypt(blocks[i]); } return(BlockCipherSupport.ConcatenateBlocks(blocks)); }
private void CipherBlocks(List <byte[]> blocks) { for (int i = 0; i < blocks.Count; i++) { BigInteger nonceCounterXor = InitializationVector ^ new BigInteger(i); byte[] nonceCounterXorBytes = rsa.Encrypt(BigIntegerExtensions.UnsignedToBytes(nonceCounterXor)); nonceCounterXor = BigIntegerExtensions.UnsignedFromBytes(nonceCounterXorBytes); BigInteger block = BigIntegerExtensions.UnsignedFromBytes(blocks[i]); block ^= nonceCounterXor; RSAParameters parameters = rsa.ExportParameters(); int keySize = parameters.Modulus.Length; blocks[i] = BlockCipherSupport.PadWithZeros(BigIntegerExtensions.UnsignedToBytes(block), keySize); } }
public byte[] Decipher(byte[] data) { RSAParameters parameters = rsa.ExportParameters(); int keySize = parameters.Modulus.Length; List <byte[]> blocks = BlockCipherSupport.DivideIntoBlocks(data, keySize); for (int i = 0; i < blocks.Count; i++) { blocks[i] = rsa.Decrypt(blocks[i]); blocks[i] = BlockCipherSupport.PadWithZeros(blocks[i], BlockSize); } return(BlockCipherSupport.RemovePadding(BlockCipherSupport.ConcatenateBlocks(blocks))); }
private List <byte[]> DecipherBlocks(List <byte[]> blocks) { List <byte[]> decipheredBlocks = new List <byte[]>(blocks.Count); for (int i = 0; i < blocks.Count; i++) { byte[] cipheredPreviousBlock = GetCipheredPreviousBlock(blocks, i); BigInteger cipheredAgainPreviousBlock = BigIntegerExtensions.UnsignedFromBytes(rsa.Encrypt(cipheredPreviousBlock)); // Cipher intended BigInteger block = BigIntegerExtensions.UnsignedFromBytes(blocks[i]); decipheredBlocks.Add(BigIntegerExtensions.UnsignedToBytes(cipheredAgainPreviousBlock ^ block)); decipheredBlocks[i] = BlockCipherSupport.PadWithZeros(decipheredBlocks[i], BlockSize); } return(decipheredBlocks); }
private List <byte[]> DecipherBlocks(List <byte[]> blocks) { List <byte[]> decipheredBlocks = new List <byte[]>(blocks.Count); for (int i = 0; i < blocks.Count; i++) { var previousXor = CalculatePreviousXor(blocks, i, decipheredBlocks); decipheredBlocks.Add(rsa.Decrypt(blocks[i])); var decipheredBlock = BigIntegerExtensions.UnsignedFromBytes(decipheredBlocks[i]); decipheredBlock ^= previousXor; decipheredBlocks[i] = BigIntegerExtensions.UnsignedToBytes(decipheredBlock).Take(BlockSize).ToArray(); decipheredBlocks[i] = BlockCipherSupport.PadWithZeros(decipheredBlocks[i], BlockSize); } return(decipheredBlocks); }
private byte[] XorWithBlockSizePadding(BigInteger beforeXorBlock, BigInteger block) { byte[] xorResult = BigIntegerExtensions.UnsignedToBytes(beforeXorBlock ^ block); return(BlockCipherSupport.PadWithZeros(xorResult, BlockSize)); }