Beispiel #1
0
 public static byte[] Create(byte[] message, byte[] nonce, byte[] key)
 {
     if (key == null || key.Length != 32)
     {
         throw new KeyOutOfRangeException("key", (key == null) ? 0 : key.Length, string.Format("key must be {0} bytes in length.", 32));
     }
     if (nonce == null || nonce.Length != 24)
     {
         throw new NonceOutOfRangeException("nonce", (nonce == null) ? 0 : nonce.Length, string.Format("nonce must be {0} bytes in length.", 24));
     }
     byte[] array = new byte[message.Length + 32];
     Array.Copy(message, 0, array, 32, message.Length);
     byte[] array2 = new byte[array.Length];
     if (SodiumLibrary.crypto_secretbox(array2, array, (long)array.Length, nonce, key) != 0)
     {
         throw new CryptographicException("Failed to create SecretBox");
     }
     return(array2);
 }