-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves random generation and adds UUID
- Loading branch information
Showing
31 changed files
with
1,550 additions
and
397 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:hashlib/hashlib.dart'; | ||
|
||
void main() { | ||
final key = "password"; | ||
final salt = "some salt"; | ||
print("key => $key"); | ||
print("salt => $salt"); | ||
print(''); | ||
|
||
final pw = key.codeUnits; | ||
final iv = salt.codeUnits; | ||
|
||
// Examples of Argon2 key derivation | ||
final argon2Test = Argon2Security.test; | ||
print("[Argon2i] => ${argon2i(pw, iv, security: argon2Test)}"); | ||
print("[Argon2d] => ${argon2d(pw, iv, security: argon2Test)}"); | ||
print("[Argon2id] => ${argon2id(pw, iv, security: argon2Test)}"); | ||
|
||
// Examples of scrypt key derivation | ||
final scryptLittle = ScryptSecurity.little; | ||
print("[scrypt] => ${scrypt(pw, iv, security: scryptLittle, dklen: 24)}"); | ||
print(''); | ||
|
||
// Examples of bcrypt key derivation | ||
final bcryptLittle = BcryptSecurity.little; | ||
print("[bcrypt] => ${bcrypt(pw, bcryptSalt(security: bcryptLittle))}"); | ||
print(''); | ||
|
||
// Examples of PBKDF2 key derivation | ||
print("SHA256/HMAC/PBKDF2 => ${pbkdf2(pw, iv).hex()}"); | ||
print("BLAKE2b-256/HMAC/PBKDF2 => ${blake2b256.pbkdf2(iv).hex(pw)}"); | ||
print("BLAKE2b-256/MAC/PBKDF2 => ${blake2b256.mac.pbkdf2(iv).hex(pw)}"); | ||
print("SHA1/HMAC/PBKDF2 => ${sha1.pbkdf2(iv, iterations: 100).hex(pw)}"); | ||
print(''); | ||
} |
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,20 @@ | ||
import 'package:hashlib/codecs.dart'; | ||
import 'package:hashlib/random.dart'; | ||
|
||
void main() { | ||
print('UUID Generation:'); | ||
print('UUIDv1: ${uuid.v1()}'); | ||
print('UUIDv3: ${uuid.v3()}'); | ||
print('UUIDv4: ${uuid.v4()}'); | ||
print('UUIDv5: ${uuid.v5()}'); | ||
print('UUIDv6: ${uuid.v6()}'); | ||
print('UUIDv7: ${uuid.v7()}'); | ||
print('UUIDv8: ${uuid.v8()}'); | ||
print(''); | ||
|
||
print('Random Generation:'); | ||
print(randomNumbers(4)); | ||
print(toHex(randomBytes(16))); | ||
print(randomString(32, lower: true, whitelist: '_'.codeUnits)); | ||
print(''); | ||
} |
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,8 @@ | ||
// Copyright (c) 2024, Sudipto Chandra | ||
// All rights reserved. Check LICENSE file for details. | ||
|
||
/// Implementation of secure random generators based on hashlib | ||
library hashlib_random; | ||
|
||
export 'package:hashlib/src/random.dart'; | ||
export 'package:hashlib/src/uuid.dart'; |
11 changes: 6 additions & 5 deletions
11
lib/src/algorithms/random/random_js.dart → lib/src/algorithms/random/generator_js.dart
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
Oops, something went wrong.