Wiki

Changes between Initial Version and Version 1 of RandomHexString

Show
Ignore:
Timestamp:
04/23/10 02:46:40 (14 years ago)
Author:
Chuck
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • RandomHexString

    v1 v1  
     1{{{ 
     2use System.Security 
     3 
     4class 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 
     16class Program 
     17 
     18        def main 
     19                print Utils.randomHexString(32) 
     20}}}