Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I Decrypt the code which is Encrypted by md5 method in PostgreSQL

Tags:

postgresql

How can I Decrypt the code which is Encrypted by md5 method in PostgreSQL.

eg: md5("logesh") returns '82e05c4839aba7c637881489bec50dd1'

How can I decrypted this code.

like image 708
Logesh Avatar asked Sep 14 '25 14:09

Logesh


1 Answers

You can't. MD5 isn't encryption. It's a one-way cryptographic hash function. With enough compute power and/or storage you can brute force md5 to figure out what the plaintext might have been but it's only one possible plaintext for that hash. It's designed to be both slow and difficult to reverse, and impossible to reverse 1:1. There are known MD5 collisions.

PostgreSQL's use of "encrypt" in WITH ENCRYPTED PASSWORD is somewhat incorrect, it should really be WITH HASHED PASSWORD. But too late to change it now.

If you want encryption look into pgcrypto which offers AES-128 routines, etc. Or do your encryption and decryption client-side where key exposure in logs, pg_stat_statements etc isn't such a concern.

like image 163
Craig Ringer Avatar answered Sep 17 '25 06:09

Craig Ringer