# PemToKey()

Parses a PEM-encoded key string into a Java key object.

**Requires Extension:** [Crypto Extension](https://download.lucee.org/#17AB52DE-B300-A94B-E058FC978BE4542D)

```
PemToKey( pem=string );
```

**Returns:** any

# Arguments

| Argument | Type | Required | Description | Default |
|----------|------|----------|-------------|---------|
| pem | string | Yes | PEM-encoded key string |  |

# Examples

```cfml
// Convert a PEM-encoded key string into a Java key object
// Useful when you've stored keys as PEM strings and need to use them for signing, encryption, etc.
keyPair = GenerateKeyPair( "RSA-2048" );

// Parse private key PEM into a PrivateKey object
privateKey = PemToKey( keyPair.private );

// Parse public key PEM into a PublicKey object
publicKey = PemToKey( keyPair.public );

// Works with any key type: RSA, EC, Ed25519
ecKeyPair = GenerateKeyPair( "P-256" );
ecPrivate = PemToKey( ecKeyPair.private );
ecPublic = PemToKey( ecKeyPair.public );

// Roundtrip: PEM -> Key object -> PEM
key = PemToKey( keyPair.private );
pem = KeyToPem( key );
```







# Categories

[Cryptography](../../categories/crypto.md)

# See Also

[KeyToJwk()](keytojwk.md), [KeyToPem()](keytopem.md)