Mysql >= 5.6.1
In Mysql, encoding or decoding in BASE64 is only possible from version 5.6.1. Previous versions give the following error:
#1305 - FUNCTION impor_website_2014.TO_BASE64 does not exist
The functions introduced in the above version were:
TO_BASE64()
Converts the argument to a coded form in base-64 and returns the result as a string with the Character and collation connection to the database. If the argument is not a string, he is converted to string before conversion. The result is NULL if the argument is NULL.
FROM_BASE64()
Catch a string coded with the base-64 rules used by TO_BASE64()
and returns the decoded result as a string binary. The result is NULL if the argument is NULL or not a string on a 64-basis.
Example of use:
SELECT TO_BASE64('abc'), FROM_BASE64(TO_BASE64('abc')); # Devolve: 'JWJj', 'abc'
Mysql < 5.6.1
There is a project on Github to solve BASE64 encoding and decoding for older versions of Mysql:
It is essentially a UDF User Defined Function aimed at creating the: base64encode()
and base64decode()
.
Example of use:
SELECT base64encode('data,binary,text,...');
SELECT base64decode('b64strings');
INSERT INTO t1 (body) VALUES (base64encode('something'));
To use, you have to build and activate:
Build
$ git clone https://github.com/y-ken/mysql-udf-base64.git
$ cd mysql-udf-base64
$ gcc -Wall -fPIC -I/usr/local/include -shared base64.c -o base64.so
$ sudo install -m 755 base64.so `mysql_config --plugindir`
Activation
mysql> CREATE FUNCTION base64encode RETURNS STRING SONAME 'base64.so';
mysql> CREATE FUNCTION base64decode RETURNS STRING SONAME 'base64.so';
Examples and method to build and activate taken from Github’s project page.
Note:
It should be pointed out that this answer is intended to deal with the above problem: The use of a function and the fact that it is giving an error when trying to use it.
Base64 does not produce the result described in encryption, Base64 is not encryption, it is only the conversion of the string to a Radix-64 standard commonly used to standardize characters, such as the case of image transfer between different systems. Any system of Encode who has the method Decode should not be used for passwords (passwords).
This giving that the function does not exist.
– fabricio_wm
If you want to protect passwords at the bank, I recommend reading the article: http://answall.com/questions/2402/comort-hash-de-passwords_safesafesafesafesafe_form
– Avelino
Base64 is not encryption, it is a representation of binary data as text. You don’t "encrypt" to Base64, you "encode" and you "decode", and that’s pretty simple to do (in the sense that it’s not useful as read protection for encoded data). Read the answers to the question by @Avelino.
– Caffé
I saw it here. This link is quite complete. Thanks.
– fabricio_wm
Base64 is pretty much the same as an open password. You should use something that is not reversible. To check the password you must do the same operation in which the user typed and compare with the BD, and not try to decode the BD to compare with the clean password.
– Bacco