\Gishiki\Security\Encryption\AsymmetricCryptography

This class represents an algorithm collection for the asymmetric encryption engine.

Note: This class uses OpenSSL for strong encryption

Summary

Methods
Properties
Constants
encrypt()
encryptReverse()
decrypt()
decryptReverse()
generateDigitalSignature()
verifyDigitalSignature()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

encrypt()

encrypt(\Gishiki\Security\Encryption\Asymmetric\PrivateKey  $key, string  $message) : string

Encrypt the given message using the given private key.

You will need the public key to decrypt the encrypted content.

You can decrypt an encrypted content with the decrypt() function.

An example of usage can be:

$default_privkey = new PrivateKey(); $encrypted_message = Cryptography::encrypt($default_privkey, "this is my important message from my beloved half");

echo "Take good care of this and give it to my GF: " . $encrypted_message;

Parameters

\Gishiki\Security\Encryption\Asymmetric\PrivateKey $key

the private key to be used to encrypt the plain message

string $message

the message to be encrypted

Throws

\InvalidArgumentException

the plain message is not a string

\Gishiki\Security\Encryption\Asymmetric\AsymmetricException

an error occurred while encrypting the given message

Returns

string —

the encrypted message

encryptReverse()

encryptReverse(\Gishiki\Security\Encryption\Asymmetric\PublicKey  $key, string  $message) : string

Encrypt the given message using the given public key.

You will need the private key to decrypt the encrypted content.

You can decrypt an encrypted content with the decryptReverse() function.

An example of usage can be:

$default_pubkey = new PublicKey(); $encrypted_message = Cryptography::encryptReverse($default_pubkey, "this is my important message from my beloved half");

echo "Take good care of this and give it to my GF: " . $encrypted_message;

Parameters

\Gishiki\Security\Encryption\Asymmetric\PublicKey $key

the public key to be used to encrypt the plain message

string $message

the message to be encrypted

Throws

\InvalidArgumentException

the plain message is not a string

\Gishiki\Security\Encryption\Asymmetric\AsymmetricException

an error occurred while encrypting the given message

Returns

string —

the encrypted message

decrypt()

decrypt(\Gishiki\Security\Encryption\Asymmetric\PublicKey  $key, string  $encryptedMsg) : string

Decrypt an encrypted message created using the encrypt() function.

The used public key must be decoupled from the private key used to generate the message.

En example usage can be:

//load the default public key $default_pubkey = new PublicKey();

//this is a message encrypted with the application's default key $encrypted_message = "...";

//decrypt the message $plain_message = Cryptography::decrypt($default_pubkey, $encrypted_message);

echo $encrypted_message;

Parameters

\Gishiki\Security\Encryption\Asymmetric\PublicKey $key

the public key to be used to decrypt the encrypted message

string $encryptedMsg

the message to be decrypted

Throws

\InvalidArgumentException

the encrypted message is not a string

\Gishiki\Security\Encryption\Asymmetric\AsymmetricException

an error occurred while decrypting the given message

Returns

string —

the encrypted message

decryptReverse()

decryptReverse(\Gishiki\Security\Encryption\Asymmetric\PrivateKey  $key, string  $encryptedMsg) : string

Decrypt an encrypted message created using the encryptReverse() function.

The used private key must be must be the corresponding public key used to generate the message.

En example usage can be:

//load the default private key $default_pubkey = new PrivateKey();

//this is a message encrypted with the application's default key $encrypted_message = "...";

//decrypt the message $plain_message = Cryptography::decryptReverse($default_privkey, $encrypted_message);

echo $encrypted_message;

Parameters

\Gishiki\Security\Encryption\Asymmetric\PrivateKey $key

the public key to be used to decrypt the encrypted message

string $encryptedMsg

the message to be decrypted

Throws

\InvalidArgumentException

the encrypted message is not a string

\Gishiki\Security\Encryption\Asymmetric\AsymmetricException

an error occurred while decrypting the given message

Returns

string —

the encrypted message

generateDigitalSignature()

generateDigitalSignature(\Gishiki\Security\Encryption\Asymmetric\PrivateKey  $key, string  $message) : string

Generate a digital signature for the given message.

The digital signature can be used to authenticate the message because a different message will produce a different digital signature.

You will be using the public key corresponding to the given private key to check the digital signature.

Example usage: $message = "who knows if this message will be modified.....";

//get the default private key $privKey = new PrivateKey();

//generate the digital signature $signature = Cryptography::generateDigitalSignature($privKey, $message);

//transmit the digital signature

Parameters

\Gishiki\Security\Encryption\Asymmetric\PrivateKey $key

the priate key to be used to generate the message

string $message

the message to be signed

Throws

\InvalidArgumentException

the given message is not a valid string

\Gishiki\Security\Encryption\Asymmetric\AsymmetricException

the error occurred while generating the message

Returns

string —

the generate digital signature

verifyDigitalSignature()

verifyDigitalSignature(\Gishiki\Security\Encryption\Asymmetric\PublicKey  $key, string  $message, string  $signature) : boolean

Check if the given digital signature belongs to the given message.

You should be calling this function with a digital signature generated with the generateDigitalSignature() function.

Usage example (continuation of the generateDigitalSignature() example):

//get the default public key $pubKey = new PublicKey();

if (Cryptography::verifyDigitalSignature($pubKey, $message, $signature)) { echo "the message was not modified"; } else { echo "the message have been modified"; }

Parameters

\Gishiki\Security\Encryption\Asymmetric\PublicKey $key

the public key associated with the private key used to generate the signature

string $message

the message to be checked

string $signature

the digital signature of the given message

Throws

\InvalidArgumentException

the given message or the given signature are not a valid string

\Gishiki\Security\Encryption\Asymmetric\AsymmetricException

the error occurred while checking the message

Returns

boolean —

true if the message digitaly signed it equal to the digital signature