madmatt / silverstripe-encrypt-at-rest

Encrypt data at rest in your database
7 stars 11 forks source link

Problem with encryption key #15

Open bryanscheele opened 6 years ago

bryanscheele commented 6 years ago

Hi,

Can somebody help me out with creating a valid encryption key? The readme says you can use any kind of string. But I got an exception from defuse\php-encryption\src\Encoding.php that I need to use a hex string. So I came up with a hex string but I can't get past the exception below.

ERROR [User Error]: Uncaught Defuse\Crypto\Exception\BadFormatException: Invalid header.
Line 175 in ......\vendor\defuse\php-encryption\src\Encoding.php
Taitava commented 6 years ago

Hi,

it's been a few months since I last used the encryption stuff, but something like this should do:

$key_object = Defuse\Crypto\Key::createNewRandomKey();
$key_string = $key_object->saveToAsciiSafeString()

(I haven't tested the code, so let me know if there's any problem.)

This uses the same php-encryption library used by this module to create the key, so I guess you have it already installed (you do if you used Composer to install this module).

If any problems occur with the encryption key, please comment back and I'll try to help you more. :)

Firesphere commented 6 years ago

It needs to be a valid HEX key, not just any random string. We need to update that bit of documentation.

bryanscheele commented 6 years ago

Thank you Taitava, that worked great!

madmatt commented 6 years ago

Sorry for that fail @brupy, that's just bad docs that were written and not updated when we switched to the newer version of the defuse module. I'll make a PR for this shortly on master.

edit: @Taitava is exactly correct, that's the correct procedure for generating a new key.