-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scram hash to table for pgbouncer on cloud instance create
- Loading branch information
1 parent
d6939fe
commit 2e334a0
Showing
4 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule Core.Services.Cloud.Scram do | ||
alias Plug.Crypto.KeyGenerator | ||
@salt_size 16 | ||
@digest_len 32 | ||
@iterations 4096 | ||
|
||
def encrypt(pwd) do | ||
salt = :crypto.strong_rand_bytes(@salt_size) | ||
pbkdf = KeyGenerator.generate(pwd, salt, iterations: @iterations, length: @digest_len) | ||
client = :crypto.mac(:hmac, :sha256, pbkdf, "Client Key") | ||
stored = :crypto.hash(:sha256, client) | ||
server = :crypto.mac(:hmac, :sha256, pbkdf, "Server Key") | ||
"SCRAM-SHA-256$#{@iterations}:#{Base.encode64(salt)}$#{Base.encode64(stored)}:#{Base.encode64(server)}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters