2009-09-07 70 views
0

出於測試目的,我有一個設置模數和私有指數,我想要導出到RSACryptoServiceProvider。這裏是我的代碼:爲什麼我無法將這些數據導入到我的RSACryptoServiceProvider? (C#.NET)

 byte[] N = 
     { 
      0x00, 0x8C, 0x35, 0x04, 0xC8, 0x40, 0xB3, 0x67, 0xD8, 0x42, 0x35, 0x78, 0xF6, 0x2A, 0x02, 0xBE, 
      0xF7, 0x1C, 0xCD, 0x9D, 0x98, 0x55, 0x16, 0x3F, 0x81, 0xA4, 0xE5, 0x3E, 0x3D, 0x38, 0x27, 0xEE, 
      0x0D, 0x8B, 0xAF, 0xB0, 0xBB, 0xBA, 0xA4, 0xE1, 0xF2, 0xB6, 0x79, 0x92, 0x5B, 0x72, 0xBA, 0xC8, 
      0xD7, 0x63, 0xA9, 0x60, 0x17, 0xB1, 0x34, 0xF1, 0xA9, 0xE3, 0x46, 0x67, 0xB8, 0x06, 0x9A, 0xCD, 
      0x59, 0x95, 0x10, 0x32, 0x74, 0x15, 0x73, 0xB1, 0x09, 0x43, 0x56, 0xA3, 0x0B, 0xE5, 0x6D, 0x2F, 
      0x29, 0xF2, 0xB6, 0x6F, 0x5D, 0xA9, 0x55, 0x19, 0x6A, 0x2E, 0xB0, 0x30, 0x6A, 0x3F, 0xAB, 0x9F, 
      0x4F, 0xCE, 0x12, 0x66, 0x28, 0xDE, 0xEB, 0x4C, 0x07, 0x9E, 0x5F, 0x24, 0x47, 0x50, 0x39, 0xB8, 
      0x8F, 0x0F, 0xB8, 0x8C, 0x62, 0x8C, 0xC7, 0xA8, 0x30, 0x8C, 0xB3, 0x27, 0xA3, 0x13, 0xBC, 0xB0, 
      0xA5 
     }; 

     byte[] D = 
     { 
      0x0D, 0x55, 0xA9, 0x8B, 0xC6, 0x23, 0x89, 0xF7, 0xD6, 0x6C, 0x31, 0x81, 0xF0, 0x02, 0xEC, 0xD8, 
      0xA1, 0xC3, 0xA8, 0x7E, 0x69, 0x71, 0x41, 0x3E, 0xFA, 0x48, 0xD7, 0x3F, 0x89, 0x4C, 0xBA, 0xE6, 
      0x4C, 0xE7, 0xBB, 0xBE, 0x4F, 0x05, 0x09, 0x7C, 0x45, 0x00, 0x90, 0xFB, 0xE3, 0x90, 0x82, 0x33, 
      0x82, 0x06, 0x04, 0xDE, 0x9B, 0xFA, 0xF6, 0x14, 0xFB, 0x49, 0xA1, 0xE9, 0xAD, 0xAF, 0x21, 0x62, 
      0x84, 0x45, 0x3F, 0xB4, 0x6C, 0x8A, 0xFF, 0xE1, 0x8C, 0x5B, 0xC9, 0xBA, 0xD5, 0xB3, 0x48, 0x57, 
      0x5A, 0xA8, 0x3F, 0x11, 0x28, 0xD3, 0xB3, 0x2F, 0xAF, 0x32, 0x29, 0xC3, 0xA4, 0x20, 0xC4, 0x03, 
      0x89, 0xD4, 0x42, 0x0D, 0xAB, 0x5F, 0x06, 0x7F, 0x57, 0xBE, 0xD1, 0x90, 0x0E, 0x5E, 0x47, 0xE8, 
      0xC8, 0xFF, 0xF3, 0x0F, 0xC2, 0xD1, 0x58, 0x9A, 0xEC, 0x66, 0x0B, 0x46, 0x9B, 0x79, 0x33, 0xC1 
     }; 

     RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); 
     RSAParameters param = new RSAParameters(); 
     param.D = D; 
     param.Modulus = N; 
     rsa.ImportParameters(param); 

不幸的是,我得到了「壞數據」。導入參數時出錯(最後一行)。 (注意:我真的很討厭這個錯誤,我經歷了幾天的測試過程才找到原因,因爲它不是描述性的 - 只要發生密碼異常就會被拋出)。

這個操作有什麼不合法的嗎?

回答

0

其實,你必須導入Exponent,否則它將無法工作。添加此行:

param.Exponent = new byte[] { 0x01, 0x00, 0x01 }; 
相關問題