MCPcopy
hub / github.com/brianc/node-postgres / md5

Function md5

packages/pg/lib/crypto/utils.js:35–48  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

33}
34
35async 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
51async function postgresMd5PasswordHash(user, password, salt) {

Callers 1

postgresMd5PasswordHashFunction · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected