Skip to content

GenerateKey Method ​

Definition ​

  • Namespace: JASE.Crypto
  • Assembly: JASE.Crypto.dll

byte[] GenerateKey(int length = null) ​

csharp
byte[] GenerateKey(int length = null)

Generates a cryptographically secure random byte array with a specified length for use as a key or IV

Parameters ​

NameDescription
lengthThe length of the byte array to generate (default: 32).

Returns ​

A randomly generated byte array.

Remarks ​

The returned array is owned by the caller and held in ordinary managed memory; the library does not track or clear it. When it represents long-lived key material, clear it (for example via System.Security.Cryptography.CryptographicOperations.ZeroMemory(System.Span{System.Byte})) once it is no longer needed.