public byte[] Encrypt(byte[] value) { // Generate the key if not already present if (_state.ProviderKey == null) { if (_rawKey == null) { _rawKey = CertificateUtilities.GenerateEncryptionKey(_publicKey.KeySize); } _state.ProviderKey = new RsaCryptoProvider(_privateKey).Encrypt(_rawKey); } // Encrypt the value return(new AesCryptoProvider(new CryptoKey(new CryptoKeyProtector("None", _rawKey))).Encrypt(value)); }