- Install PHP 8.2
- Open terminal in the project root directory and run
php -S localhost:8000
command in terminal - Open
http:https://localhost:8000
in browser - Connect to the Internet because of JQuery
You should see the following screen:
- Alice wants to send a file to Bob, but she wants to encrypt the file before sending it to Bob
- Bob sends his public key to Alice, and they agree on a symmetric key (showed on the main screen)
- In the first form, Alice selects a file, choose the key to use and clicks on the "Encrypt file" button, and she gets an encrypted file made on her client side
- In the second form, Alice selects the encrypted file and clicks on the "Send file" button, and she sends the encrypted file to Bob
- Bob decrypts the file with his private key or the symmetric key, and he gets the Alice's original file
- Bob edits Alice's file and signs it with his private key
- Bob sends edited Alice's file and his digital signature to Alice
- Alice verifies Bob's digital signature with Bob's public key, and she gets the message that the signature is valid or not to be sure that the file is from Bob and that the file is not changed
-
Used for symmetric key generation (PHP):
-
Used for symmetric encryption (JavaScript - WebCrypto):
crypto.getRandomValues
https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValuescrypto.subtle.importKey
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKeycrypto.subtle.encrypt
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt
-
Used for symmetric decryption (PHP - OpenSSL):
openssl_decrypt
https://www.php.net/manual/en/function.openssl-decrypt.php
-
Used for asymmetric key generation (PHP - OpenSSL):
openssl_pkey_new
https://www.php.net/manual/en/function.openssl-pkey-new.phpopenssl_pkey_export_to_file
https://www.php.net/manual/en/function.openssl-pkey-export-to-file.phpopenssl_pkey_get_details
https://www.php.net/manual/en/function.openssl-pkey-get-details.php
-
Used for asymmetric encryption (JavaScript - WebCrypto):
crypto.subtle.importKey
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey (it is necessary to use SHA-1 as the hash function, because of the paddingOPENSSL_PKCS1_OAEP_PADDING
in PHP OpenSSL decryption function)crypto.subtle.encrypt
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt (it is only possible to encrypt a small amount of data (190 bytes in this case - https://crypto.stackexchange.com/questions/42097/what-is-the-maximum-size-of-the-plaintext-message-for-rsa-oaep, so it is necessary to use a symmetric encryption algorithm to encrypt the data and then encrypt the key with the public key)
-
Used for asymmetric decryption (PHP - OpenSSL):
openssl_pkey_get_private
https://www.php.net/manual/en/function.openssl-pkey-get-private.phpopenssl_private_decrypt
https://www.php.net/manual/en/function.openssl-private-decrypt.phpopenssl_error_string
https://www.php.net/manual/en/function.openssl-error-string.php
Used for digital signature:
- PHP - OpenSSL
openssl_sign
https://www.php.net/manual/en/function.openssl-sign.php (this is more efficient to use for signing the message digest, but I did not use it because I needed to save message digest and signature in the separate files, so I usedopenssl_digest
andopenssl_private_encrypt
functions instead)openssl_digest
https://www.php.net/manual/en/function.openssl-digest.phpopenssl_pkey_get_private
https://www.php.net/manual/en/function.openssl-pkey-get-private.phpopenssl_private_encrypt
https://www.php.net/manual/en/function.openssl-private-encrypt.phpopenssl_pkey_get_public
https://www.php.net/manual/en/function.openssl-pkey-get-public.phpopenssl_public_decrypt
https://www.php.net/manual/en/function.openssl-public-decrypt.php
- JavaScript - WebCrypto (tryed to decrypt or verify on client side, but it did not work, so I did it on the server side)
crypto.subtle.importKey
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKeycrypto.subtle.verify
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/verify (this is more efficient to use for verifying the digital signature, but because I did digital signing manually withopenssl_digest
andopenssl_private_encrypt
functions in PHP, so I did verify manually withcrypto.subtle.digest
andcrypto.subtle.decrypt
functions)crypto.subtle.digest
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digestcrypto.subtle.decrypt
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/decrypt