KeyToPem()

edit

Converts a Java key object or Base64-encoded key to PEM format.

Requires Extension: Crypto Extension

KeyToPem( key=any, algorithm=string );

Returns: String

Argument Description
key
any, required
edit

Java Key object or Base64-encoded key string

algorithm
string, optional
edit

Algorithm name (RSA, EC, etc). Required when key is Base64-encoded. Not needed for Java Key objects or PEM strings (auto-detected).

Examples

edit
// Convert a Java key object back to a PEM string
// Useful for storing or transmitting keys
keyPair = GenerateKeyPair( "RSA-2048" );

// Convert key objects to PEM strings privateKey = PemToKey( keyPair.private ); pem = KeyToPem( privateKey ); // "-----BEGIN PRIVATE KEY-----\nMIIE..."
publicKey = PemToKey( keyPair.public ); pem = KeyToPem( publicKey ); // "-----BEGIN PUBLIC KEY-----\nMIIB..."

See also