Java.Security.SecureRandom Class
This class generates cryptographically secure pseudo-random numbers.

See Also: SecureRandom Members

Syntax

[Android.Runtime.Register("java/security/SecureRandom", DoNotGenerateAcw=true)]
public class SecureRandom : Java.Util.Random

Remarks

This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRandom using the default constructor. This will provide an instance of the most cryptographically strong provider available:

java Example

SecureRandom sr = new SecureRandom();
 byte[] output = new byte[16];
 sr.nextBytes(output);

The default algorithm is defined by the first SecureRandomSpi provider found in the installed security providers. Use Java.Security.Security to install custom Java.Security.SecureRandomSpi providers.

Note that the output of a SecureRandom instance should never be relied upon to be deterministic. For deterministic output from a given input, see Java.Security.MessageDigest which provides one-way hash functions. For deriving keys from passwords, see Javax.Crypto.SecretKeyFactory.

A seed is an array of bytes used to bootstrap random number generation. To produce cryptographically secure random numbers, both the seed and the algorithm must be secure.

By default, instances of this class will generate an initial seed using an internal entropy source, such as /dev/urandom. This seed is unpredictable and appropriate for secure use.

Using the SecureRandom(Byte[]) or calling SecureRandom.SetSeed(Byte[]) may completely replace the cryptographically strong default seed causing the instance to return a predictable sequence of numbers unfit for secure use. Due to variations between implementations it is not recommended to use setSeed at all.

[Android Documentation]

Requirements

Namespace: Java.Security
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1