{"id":269,"date":"2021-11-17T14:50:28","date_gmt":"2021-11-17T14:50:28","guid":{"rendered":"https:\/\/ouritsource.com\/blog\/?p=269"},"modified":"2021-11-17T15:17:13","modified_gmt":"2021-11-17T15:17:13","slug":"different-encryption-methods-in-mysql","status":"publish","type":"post","link":"https:\/\/ouritsource.com\/blog\/different-encryption-methods-in-mysql\/","title":{"rendered":"Different Encryption Methods in MySQL"},"content":{"rendered":"<body>\n<p>Below are examples of three different encryption methods to encrypt data inserted into a MySQL database table. <\/p>\n\n\n\n<p>A test table is created where field1 will store data in plain text and field2 will store encrypted data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE encrypt_test\n(field1 varchar(255) null,\nfield2 varchar(255));<\/code><\/pre>\n\n\n\n<p><strong>SHA1 Example<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO encrypt_test(field1,field2) VALUES ('dd',SHA1('yoda'));\nSELECT * FROM encrypt_test WHERE field2=SHA1('yoda');<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"640\" height=\"117\" src=\"https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-3.png?resize=640%2C117&#038;ssl=1\" alt=\"\" class=\"wp-image-274\" loading=\"lazy\" srcset=\"https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-3.png?w=727&amp;ssl=1 727w, https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-3.png?resize=300%2C55&amp;ssl=1 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p><strong>SHA2<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO encrypt_test(field1,field2) VALUES ('a',sha2('password',224));\nSELECT * FROM encrypt_test WHERE field2 = sha3('password',224));<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"640\" height=\"117\" src=\"https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-1.png?resize=640%2C117&#038;ssl=1\" alt=\"\" class=\"wp-image-272\" loading=\"lazy\" srcset=\"https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-1.png?w=793&amp;ssl=1 793w, https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-1.png?resize=300%2C55&amp;ssl=1 300w, https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-1.png?resize=768%2C140&amp;ssl=1 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM encrypt_test WHERE field2 = sha2('password',224));\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"640\" height=\"117\" src=\"https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-4.png?resize=640%2C117&#038;ssl=1\" alt=\"\" class=\"wp-image-276\" loading=\"lazy\" srcset=\"https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-4.png?w=793&amp;ssl=1 793w, https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-4.png?resize=300%2C55&amp;ssl=1 300w, https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-4.png?resize=768%2C140&amp;ssl=1 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p><strong>AES_ENCRYPT<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE demodb\n(value blob);\n\nINSERT INTO demodb (demo) VALUES (AES_ENCRYPT('test to encrypt','PasswordKey'));\nSELECT CAST(AES_DECRYPT(value,'PasswordKey') as CHAR) FROM demodb;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"498\" height=\"102\" src=\"https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-2.png?resize=498%2C102&#038;ssl=1\" alt=\"\" class=\"wp-image-273\" loading=\"lazy\" srcset=\"https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-2.png?w=498&amp;ssl=1 498w, https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image-2.png?resize=300%2C61&amp;ssl=1 300w\" sizes=\"auto, (max-width: 498px) 100vw, 498px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT CAST(AES_DECRYPT(value,'PasswordKey') as CHAR) = 'test to encrypt' FROM demodb;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"640\" height=\"78\" src=\"https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image.png?resize=640%2C78&#038;ssl=1\" alt=\"\" class=\"wp-image-271\" loading=\"lazy\" srcset=\"https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image.png?w=999&amp;ssl=1 999w, https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image.png?resize=300%2C37&amp;ssl=1 300w, https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2021\/11\/image.png?resize=768%2C94&amp;ssl=1 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>Below are examples of three different encryption methods to encrypt data inserted into a MySQL database table. A test table is created where field1 will store data in plain text and field2&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-269","post","type-post","status-publish","format-standard","hentry","category-miscellaneous","no-thumbnail"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/posts\/269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/comments?post=269"}],"version-history":[{"count":3,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/posts\/269\/revisions"}],"predecessor-version":[{"id":277,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/posts\/269\/revisions\/277"}],"wp:attachment":[{"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/media?parent=269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/categories?post=269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/tags?post=269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}