Search code examples
javablackberryjava-mebase64bouncycastle

Convert from RSAPrivateCrtKeyParameters / RSAKeyParameters to PEM in J2ME


I'm developing some cryptography on BlackBerry, and we're working with certificates. We use BouncyCastle Lightweight API instead of RIM api to apply the cryptography, but in the lightweight API PEMWriter doesn't work (Well, it isn't included because it needs some JCE).

public RSAPrivateCrtKeyParameters _RSAPrivateKey;
public RSAKeyParameters _RSAPublicKey;

I get this keys from the object

AsymmetricCipherKeyPair theKeyPair

So, i need a method to BASE64Encode the two keys, or how to transform this keys to other objects that can be directly transformed to base64/PEM format. I can generate the certificate manually, but i need the encoding of the keys.

I know there are methods to do this, but all require PEMWriter or APIs that are not enabled with j2ME and the bouncycastle lightweight API.


Solution

  • You could look into the PEMWriter/PEMReader code of bouncy castle and use their implementation as a reference:

    PemWriter

    PemReader