Grima
2018-08
Whispering into Alma's ear
grimas
encrypt.php
Go to the documentation of this file.
1
<?php
2
$plaintext
=
"message to be encrypted"
;
3
$cipher
=
"aes-128-ocb"
;
4
$key
= random_bytes(32);
5
6
$ivlen
= openssl_cipher_iv_length(
$cipher
);
7
print(
$ivlen
.
"\n"
);
8
print(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES.
"\n"
);
9
10
$iv
= random_bytes(
$ivlen
);
11
$ciphertext
= openssl_encrypt(
$plaintext
,
$cipher
,
$key
, $options=0,
$iv
, $tag);
12
print(strlen(
$plaintext
).
"\n"
);
13
print(strlen(
$ciphertext
).
"\n"
);
14
15
//store $cipher, $iv, and $tag for decryption later
16
17
$original_plaintext
= openssl_decrypt(
$ciphertext
,
$cipher
,
$key
, $options=0,
$iv
, $tag);
18
19
echo
$original_plaintext
.
"\n"
;
20
21
$other_plaintext
= sodium_crypto_secretbox_open(
$ciphertext
,
$iv
,
$key
);
22
23
echo
$original_plaintext
.
"\n"
;
$original_plaintext
$original_plaintext
Definition:
encrypt.php:17
$key
$key
Definition:
encrypt.php:4
$cipher
$cipher
Definition:
encrypt.php:3
$plaintext
$plaintext
Definition:
encrypt.php:2
$iv
$iv
Definition:
encrypt.php:10
$ivlen
$ivlen
Definition:
encrypt.php:6
$other_plaintext
$other_plaintext
Definition:
encrypt.php:21
$ciphertext
$ciphertext
Definition:
encrypt.php:11
Generated by
1.8.13