| 1 | {{{ |
| 2 | use System.Security |
| 3 | |
| 4 | class Utils |
| 5 | |
| 6 | shared |
| 7 | |
| 8 | def randomHexString(length as int) as String |
| 9 | """ Returns a cryptographically strong random hex string such as '43de3637ba024801'. """ |
| 10 | require length > 0 and length % 2 == 0 |
| 11 | ensure result.length == length |
| 12 | bytes = uint8[](length // 2) |
| 13 | Cryptography.RNGCryptoServiceProvider.create.getBytes(bytes) |
| 14 | return BitConverter.toString(bytes).replace('-', '').toLower |
| 15 | |
| 16 | class Program |
| 17 | |
| 18 | def main |
| 19 | print Utils.randomHexString(32) |
| 20 | }}} |