# ValidateKeyPair()

Validates that a public and private key form a matching pair.

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

```
ValidateKeyPair( privateKey=string, publicKey=string );
```

**Returns:** boolean

# Arguments

| Argument | Type | Required | Description | Default |
|----------|------|----------|-------------|---------|
| privateKey | string | Yes | Private key in PEM format |  |
| publicKey | string | Yes | Public key in PEM format |  |

# Examples

```cfml
// Check whether a private key and public key belong to the same key pair
// Accepts PEM strings or Java key objects
keyPair = GenerateKeyPair( "RSA-2048" );
isValid = ValidateKeyPair( keyPair.private, keyPair.public ); // true

// Mismatched keys return false
keyPair1 = GenerateKeyPair( "RSA-2048" );
keyPair2 = GenerateKeyPair( "RSA-2048" );
isValid = ValidateKeyPair( keyPair1.private, keyPair2.public ); // false

// Works with EC keys too
ecPair = GenerateKeyPair( "P-256" );
isValid = ValidateKeyPair( ecPair.private, ecPair.public ); // true
```







# Categories

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

# See Also

[GenerateKeyPair()](generatekeypair.md), [KeyToPem()](keytopem.md)