none
How can .NET RSA keys be used in Java? RRS feed

  • Question

  • Generating a private + public RSA key pair in .NET is very easy:

    System.Security.Cryptography.RSA rsakey = System.Security.Cryptography.RSA.Create();
    
    string privatekey = rsakey.ToXmlString(true );
    string publickey = rsakey.ToXmlString(false ); 
    
    

     

    We want to use the same keys also inside a Java application. How can we do that? Since the keys are in a Microsoft specific XML format:

     

    
    
    <RSAKeyValue>
    
    <Modulus>ntv9Up9rbzmg/i4EKE38t6NaF2EiBG7nTNiae9Igxdw0iZwUXnOkxCpKmCDDFP0lsmBozpMUVMnPaOKu4knbDfwENceK4WDoxvenVqYxwkyy2XefvFh3g2g8OjMRGNj62kTErxbrEL5zrGH2CHPaHDW6pkpcMLkj0h+XyVEVzV0=</Modulus><Exponent>AQAB</Exponent>
    
    <P>1OI61IECLgJ4EnpMUlb8ukwPsGroHwUFl6C4ZedDVNI9jvNVWB5GhgA4GEFhVzid0Op+fNY4djQSudZxIXreQQ==</P><Q> vwioycDCKJfm4nwg8vVct9ZS/AZ8VHVdy0feCSS1D4m5NFdQLo3vvRKZEGESP6zmDmaJ2Z3jVm31LVJXzsKgHQ==</Q>
    
    <DP>OpsVSw9BBF2VpLCadkiQRtFNuGmWAYQmZ/nNCfDCroU6gTIoGpwrGhTRXIwTOinR+IO10rQ+0vu+8/4/ItJqgQ==</DP><DQ> e7zOJ7CVktmhkb45UWYgomtO4TQKQGKtWEi6x01hgikBL6gGpcEGMn/jaTqXKWuCsH02eSDN6mPa1XpqqeBi+Q==</DQ><InverseQ> ZoNAaGhB1FFDyWvWsOMQjqHOgTXBt3nFIdNHYIk0ZkBEwK2gXfR5DPSjRjNjoAEcDWhzPvxy4/1gzGv0mWhkZQ==</InverseQ><D> dGV1+FrsqgNMrdDjpPB3ccpT0XuPJDZqbYjrsDvnXXIaYJWm6wnKuRzPqSWgKrnNLCStxmZH6FQyD4TAZPd+c1m269dqRcfuaRFHtMgVbz1tykzXOPmEajjc7
    
    spKg1xPqxyMYYN6OjVaY2Zekl1PLmtqWZyD+QjNlHDDDEDpXQE=</D></RSAKeyValue> 
    
    

     

     

    Tuesday, May 18, 2010 6:16 AM

Answers