Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
So If I encrypt a number using aes_encrypt() then store it in a database.
Then I try to pull that number back out using aes_decrypt() I'm left with the number followed by "����������������" What's up with these? and how do I get rid of them, I've tried to trim() them with no luck.
Ideas?
Comments
Comment #1
easyfit CreditAttribution: easyfit commentedAh yeah, that's just padding the AES algorithm adds to the string to get it to a certain length iirc. Strange that trim() doesn't work for you though, that's what I use at several places in this module and it works for me. I should probably add a default call to trim() as well on decrypt.
But anyway, in the PHP manual on trim the characters which are trimmed are listed, and again iirc, this padding consists of NULL-bytes, so it should get trimmed off, but I'm thinking maybe it's a database encoding issue? I've only tested this module on a PostgreSQL db with UTF-8 encoding, maybe you're running something like a MySQL with latin1/ISO-8859-1 encoding? It seems to me that it shouldn't matter though, since any encoding should consistently give you the exact same data back which you put in, but then I'm no expert on these things.
It's worth doing some testing, I'll get back to you later.
Comment #2
easyfit CreditAttribution: easyfit commentedI've tried encrypting/decrypting a number with a MySQL database now using latin1 encoding, but I can't reproduce your problem. I am getting the extra characters at the end of course, which is expected and normal, but they strip off just fine for me with trim().
Comment #3
vordude CreditAttribution: vordude commentedI'm sorry my ID10T Error. Was trying to pass in the � characters to the trim($mystringtotrim,��������);
Works fine with just trim($mystringtotrim);