Exemple #1
0
 public Encryption(Key key, IV iv)
 {
     aes.Mode    = CipherMode.CBC;
     aes.Padding = PaddingMode.None;
     aes.Key     = key.key;
     aes.IV      = iv.iv;
 }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }