(string)
| 33 | } |
| 34 | |
| 35 | async function md5(string) { |
| 36 | try { |
| 37 | return nodeCrypto.createHash('md5').update(string, 'utf-8').digest('hex') |
| 38 | } catch (e) { |
| 39 | // `createHash()` failed so we are probably not in Node.js, use the WebCrypto API instead. |
| 40 | // Note that the MD5 algorithm on WebCrypto is not available in Node.js. |
| 41 | // This is why we cannot just use WebCrypto in all environments. |
| 42 | const data = typeof string === 'string' ? textEncoder.encode(string) : string |
| 43 | const hash = await subtleCrypto.digest('MD5', data) |
| 44 | return Array.from(new Uint8Array(hash)) |
| 45 | .map((b) => b.toString(16).padStart(2, '0')) |
| 46 | .join('') |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // See AuthenticationMD5Password at https://www.postgresql.org/docs/current/static/protocol-flow.html |
| 51 | async function postgresMd5PasswordHash(user, password, salt) { |
no test coverage detected