interface RsaWalletServiceInterface (View source)

RSA related service functions (e.g. used for the RSA authentication provider)

Methods

string
generateNewKeypair(bool $usedForPasswords = false)

Generates a new keypair and returns a fingerprint to refer to it

string
registerKeyPairFromPrivateKeyString(string $privateKeyString, bool $usedForPasswords = false)

Adds the specified keypair to the local store and returns a fingerprint to refer to it.

string
registerPublicKeyFromString(string $publicKeyString)

Adds the specified public key to the wallet and returns a fingerprint to refer to it.

getPublicKey(string $fingerprint)

Returns the public key for the given fingerprint

string
decrypt(string $cypher, string $fingerprint)

Decrypts the given cypher with the private key identified by the given fingerprint Note: You should never decrypt a password with this function. Use checkRSAEncryptedPassword() to check passwords!

string
sign(string $plaintext, string $fingerprint)

Signs the given plaintext with the private key identified by the given fingerprint

bool
verifySignature(string $plaintext, string $signature, string $fingerprint)

Checks whether the given signature is valid for the given plaintext with the public key identified by the given fingerprint

string
encryptWithPublicKey(string $plaintext, string $fingerprint)

Encrypts the given plaintext with the public key identified by the given fingerprint

bool
checkRSAEncryptedPassword(string $encryptedPassword, string $passwordHash, string $salt, string $fingerprint)

Checks if the given encrypted password is correct by comparing it's md5 hash. The salt is appended to the decrypted password string before hashing.

void
destroyKeypair(string $fingerprint)

Destroys the keypair identified by the given fingerprint

Details

string generateNewKeypair(bool $usedForPasswords = false)

Generates a new keypair and returns a fingerprint to refer to it

Parameters

bool $usedForPasswords

true if this keypair should be used to encrypt passwords (then decryption won't be allowed!).

Return Value

string

An fingerprint that identifies the generated keypair

string registerKeyPairFromPrivateKeyString(string $privateKeyString, bool $usedForPasswords = false)

Adds the specified keypair to the local store and returns a fingerprint to refer to it.

Parameters

string $privateKeyString

The private key in its string representation

bool $usedForPasswords

true if this keypair should be used to encrypt passwords (then decryption won't be allowed!).

Return Value

string

The fingerprint used for storing

string registerPublicKeyFromString(string $publicKeyString)

Adds the specified public key to the wallet and returns a fingerprint to refer to it.

This is helpful if you have not private key and want to use this key only to verify incoming data.

Parameters

string $publicKeyString

The public key in its string representation

Return Value

string

The fingerprint used for storing

OpenSslRsaKey getPublicKey(string $fingerprint)

Returns the public key for the given fingerprint

Parameters

string $fingerprint

The fingerprint

Return Value

OpenSslRsaKey

The public key

Exceptions

InvalidKeyPairIdException

string decrypt(string $cypher, string $fingerprint)

Decrypts the given cypher with the private key identified by the given fingerprint Note: You should never decrypt a password with this function. Use checkRSAEncryptedPassword() to check passwords!

Parameters

string $cypher

Cypher text to decrypt

string $fingerprint

The fingerprint to identify to correct private key

Return Value

string

The decrypted text

Exceptions

InvalidKeyPairIdException
DecryptionNotAllowedException

string sign(string $plaintext, string $fingerprint)

Signs the given plaintext with the private key identified by the given fingerprint

Parameters

string $plaintext

The plaintext to sign

string $fingerprint

The fingerprint to identify to correct private key

Return Value

string

The signature of the given plaintext

Exceptions

InvalidKeyPairIdException

bool verifySignature(string $plaintext, string $signature, string $fingerprint)

Checks whether the given signature is valid for the given plaintext with the public key identified by the given fingerprint

Parameters

string $plaintext

The plaintext to sign

string $signature

The signature that should be verified

string $fingerprint

The fingerprint to identify to correct public key

Return Value

bool

true if the signature is correct for the given plaintext and public key

string encryptWithPublicKey(string $plaintext, string $fingerprint)

Encrypts the given plaintext with the public key identified by the given fingerprint

Parameters

string $plaintext

The plaintext to encrypt

string $fingerprint

The fingerprint to identify to correct public key

Return Value

string

The ciphertext

bool checkRSAEncryptedPassword(string $encryptedPassword, string $passwordHash, string $salt, string $fingerprint)

Checks if the given encrypted password is correct by comparing it's md5 hash. The salt is appended to the decrypted password string before hashing.

Parameters

string $encryptedPassword

The received, RSA encrypted password to check

string $passwordHash

The md5 hashed password string (md5(md5(password) . salt))

string $salt

The salt used in the md5 password hash

string $fingerprint

The fingerprint to identify to correct private key

Return Value

bool

true if the password is correct

void destroyKeypair(string $fingerprint)

Destroys the keypair identified by the given fingerprint

Parameters

string $fingerprint

The fingerprint

Return Value

void

Exceptions

InvalidKeyPairIdException