ValidateKeyPair()

edit

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

Requires Extension: Crypto Extension

ValidateKeyPair( privateKey=string, publicKey=string );

Returns: Boolean

Argument Description
privateKey
string, required
edit

Private key in PEM format

publicKey
string, required
edit

Public key in PEM format

Examples

edit
// 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

See also