public Encryption(Key key, IV iv) { aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.None; aes.Key = key.key; aes.IV = iv.iv; }
public void EncryptFileWithPadding(FileStream input, int contentID, FileStream output, int blockSize) { BigEndianMemoryStream ivStream = new BigEndianMemoryStream(0x10); ivStream.WriteBigEndian((short)contentID); IV iv = new IV(ivStream.GetBuffer()); EncryptSingleFile(input, output, input.Length, iv, blockSize); }
public void EncryptFileWithPadding(FST fst, string outputFilename, short contentID, int blockSize) { using FileStream output = new FileStream(outputFilename, FileMode.Create); MemoryStream input = new MemoryStream(fst.GetAsData()); BigEndianMemoryStream ivStream = new BigEndianMemoryStream(0x10); ivStream.WriteBigEndian(contentID); IV iv = new IV(ivStream.GetBuffer()); EncryptSingleFile(input, output, fst.GetDataSize(), iv, blockSize); }
private void EncryptSingleFile(Stream input, Stream output, long inputLength, IV iv, int blockSize) { aes.IV = iv.iv; long targetSize = Utils.Align(inputLength, blockSize); int cur_position = 0; do { byte[] blockBuffer = new byte[blockSize]; input.Read(blockBuffer, 0, blockSize); blockBuffer = Encrypt(blockBuffer); aes.IV = Utils.CopyOfRange(blockBuffer, blockSize - 16, blockSize); cur_position += blockSize; output.Write(blockBuffer); } while (cur_position < targetSize); }