Tests for common OpenSSL based encryption functions, their generalizability to different cipher modes and related utility functions in hcuCommon.i
Definition at line 13 of file sharedHcuCommonTest.php.
◆ test_corrputed_hash_auth_openssl_aes_256_cbc_sha256()
| SharedLibraryHcuCommonTest::test_corrputed_hash_auth_openssl_aes_256_cbc_sha256 |
( |
| ) |
|
Test Case: This is an aes-256-cbc encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash is lowercase hexits. Tests the corrupted authentication hash of the encrypted text.
@expectedException Exception @expectedExceptionCode 2 @expectedExceptionMessage Hash doesn't match!
Definition at line 328 of file sharedHcuCommonTest.php.
329 $original_message =
"This is an aes-256-cbc encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash is lowercase hexits.";
331 $mthd =
"aes-256-cbc";
332 $auth_algo =
"sha256";
333 $auth_hash_bin =
false;
336 $ciphertext = hcuOpenSSLEncrypt($original_message,
339 $auth_hash_algo=$auth_algo,
340 $auth_hash_binary=$auth_hash_bin);
343 $received_hash = $ciphertext[
"hash"];
344 $corrupted_str =
"corrupt_text";
345 $hash_length = strlen($received_hash);
346 $corrupt_str_len = strlen($corrupted_str);
347 $corrputed_hash = substr_replace($received_hash,
349 $hash_length - $corrupt_str_len,
353 $decrypted_message = hcuOpenSSLDecrypt($ciphertext[
"message"],
357 $auth_hash_algo=$auth_algo,
358 $auth_hash_binary=$auth_hash_bin);
◆ test_invalid_hash_algo_openssl_aes_256_cbc()
| SharedLibraryHcuCommonTest::test_invalid_hash_algo_openssl_aes_256_cbc |
( |
| ) |
|
Test Case: Tests for catching exception on providing invalid hash algorithm for encrytpion authentication.
@expectedException Exception @expectedExceptionCode 2 @expectedExceptionMessageRegExp /Invalid hash algorithm:?\s*\w+/
Definition at line 371 of file sharedHcuCommonTest.php.
372 $original_message =
"This is an aes-256-cbc encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash is raw binary.";
374 $mthd =
"aes-256-cbc";
375 $auth_algo =
"invalid_hash_algo";
376 $auth_hash_bin =
true;
378 $ciphertext = hcuOpenSSLEncrypt($original_message,
381 $auth_hash_algo=$auth_algo,
382 $auth_hash_binary=$auth_hash_bin);
◆ test_openssl_aes_256_cbc_sha1_hexits_hash()
| SharedLibraryHcuCommonTest::test_openssl_aes_256_cbc_sha1_hexits_hash |
( |
| ) |
|
Test Case: This tests aes-256-cbc encrypted text with openssl! Authentication hashing algorithm is sha1 and the generated hash are lowercase hexits
Definition at line 137 of file sharedHcuCommonTest.php.
138 $original_message =
"This is an aes-256-cbc encrypted text with openssl! Authentication hashing algorithm is sha1 and the generated hash are lowercase hexits.";
140 $mthd =
"aes-256-cbc";
143 $auth_hash_bin =
false;
145 $ciphertext = hcuOpenSSLEncrypt($original_message,
148 $auth_hash_algo=$auth_algo,
149 $auth_hash_binary=$auth_hash_bin);
151 $decrypted_message = hcuOpenSSLDecrypt($ciphertext[
"message"],
155 $auth_hash_algo=$auth_algo,
156 $auth_hash_binary=$auth_hash_bin);
158 $this->assertEquals($original_message, $decrypted_message);
◆ test_openssl_aes_256_cbc_sha1_raw_default()
| SharedLibraryHcuCommonTest::test_openssl_aes_256_cbc_sha1_raw_default |
( |
| ) |
|
Test Case: This tests an aes-256-cbc encrypted text with openssl! Test with default optional arguments. Authentication hashing algorithm is sha1 and the generated hash is raw binary.
Definition at line 98 of file sharedHcuCommonTest.php.
99 $original_message =
"This is an aes-256-cbc encrypted text with openssl! Test with default optional arguments. Authentication hashing algorithm is sha1 and the generated hash is raw binary.";
101 $mthd =
"aes-256-cbc";
104 $auth_hash_bin =
true;
107 $ciphertext = hcuOpenSSLEncrypt($original_message,
110 $auth_hash_algo=$auth_algo,
111 $auth_hash_binary=$auth_hash_bin);
112 $decrypted_message = hcuOpenSSLDecrypt($ciphertext[
"message"],
116 $auth_hash_algo=$auth_algo,
117 $auth_hash_binary=$auth_hash_bin);
118 $this->assertEquals($original_message, $decrypted_message);
121 $ciphertext_from_default_call =hcuOpenSSLEncrypt($decrypted_message,
123 $decrypted_message_from_default_call = hcuOpenSSLDecrypt(
124 $ciphertext_from_default_call[
"message"],
125 $ciphertext_from_default_call[
"hash"],
127 $this->assertEquals($decrypted_message, $decrypted_message_from_default_call);
128 $this->assertEquals($decrypted_message_from_default_call, $original_message);
◆ test_openssl_aes_256_cbc_sha256()
| SharedLibraryHcuCommonTest::test_openssl_aes_256_cbc_sha256 |
( |
| ) |
|
Test Case: This tests an aes-256-cbc encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash is tested for both raw binary and hexits.
Definition at line 167 of file sharedHcuCommonTest.php.
168 $original_message =
"This is an aes-256-cbc encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash is tested for both raw binary and hexits.";
170 $mthd =
"aes-256-cbc";
171 $auth_algo =
"sha256";
173 foreach(array(
true,
false) as $auth_hash_bin) {
174 $ciphertext = array(
"message" =>
"",
"hash" =>
"");
175 $ciphertext = hcuOpenSSLEncrypt($original_message,
178 $auth_hash_algo=$auth_algo,
179 $auth_hash_binary=$auth_hash_bin);
181 $decrypted_message = hcuOpenSSLDecrypt($ciphertext[
"message"],
185 $auth_hash_algo=$auth_algo,
186 $auth_hash_binary=$auth_hash_bin);
188 $this->assertEquals($original_message, $decrypted_message);
◆ test_openssl_aes_256_ecb_sha256()
| SharedLibraryHcuCommonTest::test_openssl_aes_256_ecb_sha256 |
( |
| ) |
|
Test Case: This tests an aes-256-ecb encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash are raw binary. Initialization vector (IV) is also a part of the ciphertext. However, ECB does not use IV (i.e. iv size is zero) and is ignored. Therefore the main openssl based encrypt and decrypt functions should be agnoistic of the iv size (or choice of cipher mode) as well.
Definition at line 201 of file sharedHcuCommonTest.php.
202 $original_message =
"This is an aes-256-ecb encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash are raw binary. Initialization vector (IV) is also a part of the ciphertext. However, ECB does not use IV (i.e. iv size is zero). Therefore the main openssl based encrypt and decrypt functions should be agnoistic of the iv size (or choice of cipher mode) as well.";
204 $mthd =
"aes-256-ecb";
205 $auth_algo =
"sha256";
207 foreach(array(
true,
false) as $auth_hash_bin) {
208 $ciphertext = array(
"message" =>
"",
"hash" =>
"");
209 $ciphertext = hcuOpenSSLEncrypt($original_message,
212 $auth_hash_algo=$auth_algo,
213 $auth_hash_binary=$auth_hash_bin);
215 $decrypted_message = hcuOpenSSLDecrypt($ciphertext[
"message"],
219 $auth_hash_algo=$auth_algo,
220 $auth_hash_binary=$auth_hash_bin);
222 $this->assertEquals($original_message, $decrypted_message);
◆ test_openssl_auth_hash_correct_algo()
| SharedLibraryHcuCommonTest::test_openssl_auth_hash_correct_algo |
( |
| ) |
|
Test encryption authentication hash generation function
Definition at line 60 of file sharedHcuCommonTest.php.
61 $message =
"test data for authentication hash";
62 $auth_hash_algo =
"sha256";
64 foreach(array(
true,
false) as $auth_hash_binary) {
66 $hash_1 = getEncryptionAuthHash($message,
70 $hash_2 = getEncryptionAuthHash($message,
74 $this->assertTrue($hash_1 == $hash_2);
77 $seed = openssl_random_pseudo_bytes(8);
78 $hash_3 = getEncryptionAuthHash($message,
82 $hash_4 = getEncryptionAuthHash($message,
86 $this->assertTrue($hash_3 == $hash_4);
◆ test_openssl_cast5_ecb_sha256()
| SharedLibraryHcuCommonTest::test_openssl_cast5_ecb_sha256 |
( |
| ) |
|
This tests cast5-ecb encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash are tested for both raw and hexits.
Definition at line 293 of file sharedHcuCommonTest.php.
294 $original_message =
"This is cast5-ecb encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash are tested for both raw and hexits.";
297 $auth_algo =
"sha256";
299 foreach(array(
false,
true) as $auth_hash_bin){
300 $ciphertext = array(
"message" =>
"",
"hash" =>
"");
301 $ciphertext = hcuOpenSSLEncrypt($original_message,
304 $auth_hash_algo=$auth_algo,
305 $auth_hash_binary=$auth_hash_bin);
307 $decrypted_message = hcuOpenSSLDecrypt($ciphertext[
"message"],
311 $auth_hash_algo=$auth_algo,
312 $auth_hash_binary=$auth_hash_bin);
313 $this->assertEquals($original_message, $decrypted_message);
◆ test_openssl_des_ede3_cbc_sha256()
| SharedLibraryHcuCommonTest::test_openssl_des_ede3_cbc_sha256 |
( |
| ) |
|
Test Case: This tests des-ede3-cbc encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash are tested for both raw and hexits
Definition at line 232 of file sharedHcuCommonTest.php.
233 $original_message =
"This is a des-ede3-cbc encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash are tested for both raw and hexits.";
235 $mthd =
"des-ede3-cbc";
236 $auth_algo =
"sha256";
238 foreach(array(
false,
true) as $auth_hash_bin){
239 $ciphertext = array(
"message" =>
"",
"hash" =>
"");
240 $ciphertext = hcuOpenSSLEncrypt($original_message,
243 $auth_hash_algo=$auth_algo,
244 $auth_hash_binary=$auth_hash_bin);
246 $decrypted_message = hcuOpenSSLDecrypt($ciphertext[
"message"],
250 $auth_hash_algo=$auth_algo,
251 $auth_hash_binary=$auth_hash_bin);
253 $this->assertEquals($original_message, $decrypted_message);
◆ test_openssl_des_ede3_ecb_sha256()
| SharedLibraryHcuCommonTest::test_openssl_des_ede3_ecb_sha256 |
( |
| ) |
|
Test Case: This tests des-ede3 [ecb] encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash are tested for both raw and hexits.
Definition at line 263 of file sharedHcuCommonTest.php.
264 $original_message =
"This is des-ede3 [ecb] encrypted text with openssl! Authentication hashing algorithm is sha256 and the generated hash are tested for both raw and hexits.";
267 $auth_algo =
"sha256";
269 foreach(array(
false,
true) as $auth_hash_bin){
270 $ciphertext = array(
"message" =>
"",
"hash" =>
"");
271 $ciphertext = hcuOpenSSLEncrypt($original_message,
274 $auth_hash_algo=$auth_algo,
275 $auth_hash_binary=$auth_hash_bin);
277 $decrypted_message = hcuOpenSSLDecrypt($ciphertext[
"message"],
281 $auth_hash_algo=$auth_algo,
282 $auth_hash_binary=$auth_hash_bin);
284 $this->assertEquals($original_message, $decrypted_message);
◆ test_openssl_encryption_mode_agnostic_nature()
| SharedLibraryHcuCommonTest::test_openssl_encryption_mode_agnostic_nature |
( |
| ) |
|
Test Case: Tests openssl encryption api with several popular aes 256bits key size based aes encryption modes. Our openssl encryption implementation is expected to work properly for the listed encryption modes at the least.
Definition at line 392 of file sharedHcuCommonTest.php.
394 $openssl_aes_256_modes = array(
"aes-256-ctr",
402 $auth_algo =
"sha256";
403 $auth_hash_bin =
true;
405 $previous_decrypted_data =
"";
406 foreach($openssl_aes_256_modes as $aes_cipher_mode) {
407 $openssl_ciphertext = array(
"message" =>
"",
"hash" =>
"");
408 $obtained_decrypted_text =
"";
411 $openssl_ciphertext = hcuOpenSSLEncrypt($this->trusted_data,
413 $method=$aes_cipher_mode,
414 $auth_hash_algo=$auth_algo,
415 $auth_hash_binary=$auth_hash_bin);
422 $obtained_decrypted_text = hcuOpenSSLDecrypt($openssl_ciphertext[
"message"],
423 $openssl_ciphertext[
"hash"],
425 $method=$aes_cipher_mode,
426 $auth_hash_algo=$auth_algo,
427 $auth_hash_binary=$auth_hash_bin);
429 $this->assertEquals($obtained_decrypted_text, $this->trusted_data);
431 if ($previous_decrypted_data !=
"") {
432 $this->assertEquals($previous_decrypted_data, $obtained_decrypted_text);
435 $previous_decrypted_dat = $obtained_decrypted_text;
◆ test_openssl_key_generation()
| SharedLibraryHcuCommonTest::test_openssl_key_generation |
( |
| ) |
|
Test default key generation function for openssl encryption
Definition at line 26 of file sharedHcuCommonTest.php.
30 $enc_key_1 = getOpenSSLKey($this->key_suffix);
31 $enc_key_2 = getOpenSSLKey($this->key_suffix);
32 $this->assertEquals(strlen($enc_key_1), 32);
33 $this->assertEquals(strlen($enc_key_2), 32);
34 $this->assertTrue($enc_key_1 == $enc_key_2);
37 $seed = openssl_random_pseudo_bytes(8);
38 $enc_key_3 = getOpenSSLKey($seed);
39 $enc_key_4 = getOpenSSLKey($seed);
40 $this->assertEquals(strlen($enc_key_3), 32);
41 $this->assertEquals(strlen($enc_key_4), 32);
42 $this->assertTrue($enc_key_3 == $enc_key_4);
◆ test_openssl_key_generation_invalid_size()
| SharedLibraryHcuCommonTest::test_openssl_key_generation_invalid_size |
( |
| ) |
|
Test for invalid bit size input
@expectedException Exception @expectedExceptionCode 3 @expectedExceptionMessageRegExp /Invalid key size.?\s*\w+/
Definition at line 52 of file sharedHcuCommonTest.php.
53 $seed = openssl_random_pseudo_bytes(8);
54 getOpenSSLKey($seed, $bit_size=
'invalid');
The documentation for this class was generated from the following file: