haveno-app/lib/utils/salt.dart
2024-08-19 21:35:24 +01:00

16 lines
418 B
Dart

import 'dart:math';
String generateHexSalt([int length = 32]) {
final secureRandom = Random.secure();
final saltBytes =
List<int>.generate(length, (i) => secureRandom.nextInt(256));
return bytesToHex(saltBytes);
}
String bytesToHex(List<int> bytes) {
final buffer = StringBuffer();
for (var byte in bytes) {
buffer.write(byte.toRadixString(16).padLeft(2, '0'));
}
return buffer.toString();
}