Beispiel #1
0
 public static byte[] OpenDetached(byte[] cipherText, byte[] mac, byte[] nonce, byte[] secretKey, byte[] publicKey)
 {
     if (secretKey == null || secretKey.Length != 32)
     {
         throw new KeyOutOfRangeException("secretKey", (secretKey == null) ? 0 : secretKey.Length, string.Format("key must be {0} bytes in length.", 32));
     }
     if (publicKey == null || publicKey.Length != 32)
     {
         throw new KeyOutOfRangeException("publicKey", (publicKey == null) ? 0 : secretKey.Length, string.Format("key must be {0} bytes in length.", 32));
     }
     if (mac == null || mac.Length != 16)
     {
         throw new MacOutOfRangeException("mac", (mac == null) ? 0 : mac.Length, string.Format("mac must be {0} bytes in length.", 16));
     }
     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[cipherText.Length];
     if (SodiumLibrary.crypto_box_open_detached(array, cipherText, mac, (long)cipherText.Length, nonce, secretKey, publicKey) != 0)
     {
         throw new CryptographicException("Failed to open public detached Box");
     }
     return(array);
 }