PHP Openssl расшифровывает шифрование AES MysqlPhp

Кемеровские программисты php общаются здесь
Ответить
Гость
 PHP Openssl расшифровывает шифрование AES Mysql

Сообщение Гость »


Итак, я просто выполняю базовое шифрование данных в своих таблицах MySQL. Я следовал рекомендациям, найденным здесь
https://dev.mysql.com/doc/refman/5.6/en ... es-encrypt

< p>Но у меня возникла проблема. Хотя я знаю, что могу просто использовать aes_decrypt в запросе MySQL для расшифровки данных. Я также хочу, чтобы PHP мог делать это сам.

У меня эта часть работает. Если MySQL выполняет базовый AES_ENCRYPTION следующим образом:

Код: Выделить всё

INSERT INTO tablename (dataset) VALUES (AES_ENCRYPT('testvalue','mysecretphrase'))
I'm able to decrypt this with php like so

Код: Выделить всё

openssl_decrypt(base64_encode($dR['dataset']), 'aes-128-ecb', 'mysecretphrase')
My problem shows up when i use the recommended UNHEX(SHA2('mysecretphrase',512)) that MySQL mentions in the url above.

The php sha* functions i tried using and can confirm that they both generate the same string as MySQLs sha2()

Код: Выделить всё

openssl_digest('mysecretphrase', 'sha512')
// AND
hash('sha512', 'mysecretphrase')
And lastly to work around the UNHEX() that mysql uses, after some research I turns out that PHP hex2bin == unhex http://www.php.net/manual/en/function.hex2bin.php

However, i'm just not getting any result when decrypting the data. This is where it keeps failing. I feel as though i'm either missing something but this just does not decrypt the data and only returns empty results.

Код: Выделить всё

openssl_decrypt(base64_encode($dR['dataset']), 'aes-128-ecb', hex2bin(openssl_digest('mysecretphrase', 'sha512')))
Any help, pointers or hints would be greatly appreciated.


Источник: https://stackoverflow.com/questions/492 ... encryption
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»