예제 #1
0
        internal void Encrypt()
        {
            Contract.Requires(CurrentState == State.Empty || CurrentState == State.Decrypted);
            Contract.Ensures(CurrentState == State.Encrypted);

            var aes = new AESManaged();

            aes.SetEncryptKey(Owner.Credential.SFSEncryptKey, 128);
            Contract.Assert(Arch.ArchDefinition.PageSize % AESManaged.AES_BLOCK_SIZE == 0);

            for (int i = 0; i < Arch.ArchDefinition.PageSize / AESManaged.AES_BLOCK_SIZE; ++i)
            {
                var block = Buffer.Slice(i * AESManaged.AES_BLOCK_SIZE, AESManaged.AES_BLOCK_SIZE);
                aes.Encrypt(block, block);
            }

            CurrentState = State.Encrypted;
        }
예제 #2
0
        internal void Decrypt()
        {
            Contract.Requires(CurrentState == State.Verified);
            Contract.Ensures(CurrentState == State.Decrypted);
            Contract.Ensures(Next == Contract.OldValue(Next));

            var aes = new AESManaged();
            aes.SetDecryptKey(Owner.Credential.SFSEncryptKey, 128);
            Contract.Assert(Arch.ArchDefinition.PageSize % AESManaged.AES_BLOCK_SIZE == 0);

            for (int i = 0; i < Arch.ArchDefinition.PageSize / AESManaged.AES_BLOCK_SIZE; ++i)
            {
                var block = Buffer.Slice(i * AESManaged.AES_BLOCK_SIZE, AESManaged.AES_BLOCK_SIZE);
                aes.Decrypt(block, block);
            }

            CurrentState = State.Decrypted;
        }