Secure Coding mailing list archives
RE: Java -> .NET RSA Encryption
From: "Flanagan, Kevin" <Kevin.Flanagan () bmwfs com>
Date: Thu, 31 Mar 2005 22:28:30 +0100
Not sure about Java, but in .NET you can leverage the CryptoAPI to create a
key pair and store the public key and private key part in separate XML
blobs. I then took it a step further and write them out to files.
I am not sure how standard the XML structure is or if there is a java
equivalent to the MS Crypto API.
Here is the C# code that I use to generate RSA key pairs:
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
public class KeyGen
{
public static void Main(String[] args)
{
int numKeySize = 2048;
try
{
if (args.Length == 1)
numKeySize =
System.Convert.ToInt32(args[0].ToString(),10);
RSACryptoServiceProvider rsa =new
RSACryptoServiceProvider(numKeySize);
// Save the public key info out to pubkey
FileStream fs = new
FileStream("pubkey.key",FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write(rsa.ToXmlString(false));
sw.Close();
// Save the priate key info out to privkey
fs = new FileStream("privkey.key",FileMode.Create);
sw = new StreamWriter(fs);
sw.Write(rsa.ToXmlString(true));
sw.Close();
}
catch (System.Exception e)
{
Console.Write ("Error: " + e.ToString());
}
}
}
-----Original Message-----
From: john bart [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 31, 2005 1:12 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED];
[EMAIL PROTECTED]; [EMAIL PROTECTED];
[EMAIL PROTECTED]
Subject: RE: Java -> .NET RSA Encryption
What are the main steps to generate a key pair, put the private in the .NET
environment and the public in java keystore?
A tip regarding the exchange of keys: Traditional Java keystores does not allow you to import or export a private key. Only to generate it >in the keystore. However, you can load a PKCS12 (pfx) file as a keystore instead. So by generating the keys using OpenSSL and packaging them as a PKCS12-package you can >make them available for both platforms without installing additional providers. Regards Fredr!k
_________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
Current thread:
- Java -> .NET RSA Encryption john bart (Mar 29)
- <Possible follow-ups>
- SV: Java -> .NET RSA Encryption Fredrik Hesse (Mar 30)
- RE: Java -> .NET RSA Encryption john bart (Mar 31)
- RE: Java -> .NET RSA Encryption Flanagan, Kevin (Mar 31)
