1

を使用して生成される単純なブロブ

CryptExportKey(hKey, hPublicKey, SIMPLEBLOB, 0, lpData, &nSize);

次のコードから生成されたものと一致しません ( client.key は、http://www.codeproject.com/KB/security/plaintextsessionkey.aspxを使用して見つけた hKey のプレーン テキスト キー値であることに注意してください) 。

CspParameters cspParams = new CspParameters();            
cspParams.KeyContainerName = "Container Name";            
cspParams.KeyNumber = (int)KeyNumber.Exchange;
cspParams.ProviderType = 1;            
cspParams.ProviderName = "Microsoft Enhanced Cryptographic Provider v1.0";            cspParams.Flags = CspProviderFlags.UseMachineKeyStore;            

RSACryptoServiceProvider rsaClient = new RSACryptoServiceProvid(cspParams);               

    rsaClient.ImportCspBlob(File.ReadAllBytes(@"C:\client.key"));//Generate a SIMPLEBLOB session key

byte[] session = GetRC4SessionBlobFromKey(keyMaterial, rsaClient);//Encrypt a key using public key and write it in a SIMPLEBLOB format


   public byte[] GetRC4SessionBlobFromKey(byte[] keyData, RSACryptoServiceProvider publicKey)        
{              
using(MemoryStream ms = new MemoryStream())              
using(BinaryWriter w = new BinaryWriter(ms))            
{                   
w.Write((byte) 0x01); // SIMPLEBLOB                    
w.Write((byte) 0x02); // Version 2                    
w.Write((byte) 0x00); // Reserved                    
w.Write(0x00006801);  // ALG_ID = RC4 for the encrypted key.                
w.Write(0x0000a400);  // CALG_RSA_KEYX                    
w.Write(publicKey.Encrypt(keyData, false));                
w.Flush();                

return ms.ToArray();              
}        
}

何故ですか?

4

2 に答える 2

0

私は自分の質問を編集できないので、あなたが私に添付してほしいコンテンツをこの回答に入れています。下のビジュアルスタジオのバイナリエディタ/イミディエイトウィンドウからの画像のスクリーンキャプチャを持っています

CryptExportKey-SIMPLEBLOB

CryptExportKey-SIMPLEBLOB http://img14.imageshack.us/img14/1926/cryptoexportkeysimplebl.jpg

デバッグウィンドウのKeyMaterial値

デバッグウィンドウのキーマテリアル値http://img19.imageshack.us/img19/4138/keymaterialdebugwindow.jpg

コードプロジェクトの記事を使用してファイルに保存される主要なマテリアル値

コードプロジェクトの記事http://img243.imageshack.us/img243/7936/keymaterialfile.jpgを使用してファイルに保存されるキーマテリアルの値

GetRC4SessionBlobFromKey()からのセッションキー値(コンマで区切られた個々のバイトの整数値)

GetRC4SessionBlobFromKeyからのセッションキー値http://img206.imageshack.us/img206/5620/sessionvaluefromgetrc4s.jpg

これを調査していただきありがとうございます。さらに情報があればお知らせください。

于 2009-04-14T10:12:42.997 に答える