noalyss
Version-9
html
decrypt.php
Go to the documentation of this file.
1
<?php
2
3
// Store a string into the variable which
4
// need to be Encrypted
5
$simple_string
=
"Welcome to GeeksforGeeks"
;
6
7
// Display the original string
8
echo
"Original String: "
.
$simple_string
.
"\n"
;
9
10
// Store cipher method
11
$ciphering
=
"BF-CBC"
;
12
13
// Use OpenSSl encryption method
14
$iv_length
= openssl_cipher_iv_length(
$ciphering
);
15
$options
= 0;
16
17
// Use random_bytes() function which gives
18
// randomly 16 digit values
19
$encryption_iv
= random_bytes(8);
20
21
// Alternatively, we can use any 16 digit
22
// characters or numeric for iv
23
$encryption_key
= openssl_digest(php_uname(),
'MD5'
, TRUE);
24
25
// Encryption of string process starts
26
$encryption
= openssl_encrypt(
$simple_string
,
$ciphering
,
27
$encryption_key
,
$options
,
$encryption_iv
);
28
29
// Display the encrypted string
30
echo
"Encrypted String: "
.
$encryption
.
"\n"
;
31
32
// Decryption of string process starts
33
// Used random_bytes() which gives randomly
34
// 16 digit values
35
$decryption_iv
= 0;
36
37
// Store the decryption key
38
$decryption_key
= openssl_digest(php_uname(),
'MD5'
, TRUE);
39
40
// Descrypt the string
41
$decryption
= openssl_decrypt (
$encryption
,
$ciphering
,
42
$decryption_key
,
$options
,
$encryption_iv
);
43
44
// Display the decrypted string
45
echo
"Decrypted String: "
.
$decryption
;
46
47
?>
$options
$options
Definition:
decrypt.php:15
$decryption_iv
$decryption_iv
Definition:
decrypt.php:35
$encryption_key
$encryption_key
Definition:
decrypt.php:23
$iv_length
$iv_length
Definition:
decrypt.php:14
$encryption
$encryption
Definition:
decrypt.php:26
$decryption_key
$decryption_key
Definition:
decrypt.php:38
$ciphering
$ciphering
Definition:
decrypt.php:11
$encryption_iv
$encryption_iv
Definition:
decrypt.php:19
$simple_string
$simple_string
Definition:
decrypt.php:5
$decryption
$decryption
Definition:
decrypt.php:41