C# でT-SQL DecryptByPassPhrase をレプリケートした後、MSSQL で単純な暗号化を取得して C# で復号化することができません。テーブルは定期的に Excel と Access にエクスポートされるため、特定の列の暗号化された値が必要です。開発者がビューなどを (再) 実行する必要がなく、単純な暗号化で値を "ブロック" するのに十分です。
SQL Server 2012 の場合:
select EncryptByPassPhrase( N'hello' , N'world' )
-- returns 0x01000000AA959FFB3A8E4B06B734051437E198C8B72000A058ACE91D617123DA102287EB
C# の場合:
byte[] buf = System.Text.Encoding.UTF8.GetBytes( "0x010000003A95FA870ED699A5F90D33C2BF01491D9132F61BA162998E96F37117AF5DA0905D51EB6FB298EC88" );
// bytes emitted from the database
var cp = new TripleDESCryptoServiceProvider();
var m = new MemoryStream(buf);
cp.Key = System.Text.Encoding.UTF8.GetBytes( "hello" ); // throws
cp.IV = System.Text.Encoding.UTF8.GetBytes( "hello" ); // throws
CryptoStream cs = new CryptoStream( m , cp.CreateDecryptor( cp.Key , cp.IV ) , CryptoStreamMode.Read );
StreamReader reader = new StreamReader( cs );
string plainText = reader.ReadToEnd();
動作する C# コードはどのように見えるべきですか?
ありがとう。