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; }
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; }