Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve crypto hashing APIs to add salt #1517

Closed
ldclakmal opened this issue Jun 22, 2021 · 0 comments · Fixed by ballerina-platform/module-ballerina-crypto#228
Closed

Improve crypto hashing APIs to add salt #1517

ldclakmal opened this issue Jun 22, 2021 · 0 comments · Fixed by ballerina-platform/module-ballerina-crypto#228
Assignees
Labels
Area/Security Issues related to stdlib security module/crypto Team/PCM Protocol connector packages related issues Type/Improvement

Comments

@ldclakmal
Copy link
Member

Description:
The current hashing APIs of ballerina/crypto library does not support to add "salt".
Ex. crypto:hashSha256(password)

It would better to improve the existing APIs for the above use case.
Suggested API: public isolated function hashSha256(byte[] input, byte[] salt) returns byte[]

Java Implementation:

SecureRandom random = new SecureRandom();
byte[] salt = new byte[16];
random.nextBytes(salt);

byte[] password = "alice@123".getBytes();

MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(salt);
byte[] hashedPassword = md.digest(password);

With this approach, there can be another requirement for the use cases of secure random generators. Refer to the "Secure Random Number" section under "Crypto" tab of "[Research] Comparison on Ballerina Security Features / APIs" [1].

Also, there should be a hash verification API as well.

[1] https://docs.google.com/spreadsheets/d/1PyMAlAvgkEL0RpW8CVUj1ccW_61Vm6SMbvadFVYRpSA/edit?usp=sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Security Issues related to stdlib security module/crypto Team/PCM Protocol connector packages related issues Type/Improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant