コード例 #1
0
 public static byte[] Open(byte[] cipherText, 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 (nonce == null || nonce.Length != 24)
     {
         throw new NonceOutOfRangeException("nonce", (nonce == null) ? 0 : nonce.Length, string.Format("nonce must be {0} bytes in length.", 24));
     }
     if (cipherText[0] == 0)
     {
         bool flag = true;
         for (int i = 0; i < 15; i++)
         {
             if (cipherText[i] != 0)
             {
                 flag = false;
                 break;
             }
         }
         if (flag)
         {
             byte[] array = new byte[cipherText.Length - 16];
             Array.Copy(cipherText, 16, array, 0, cipherText.Length - 16);
             cipherText = array;
         }
     }
     byte[] array2 = new byte[cipherText.Length - 16];
     if (SodiumLibrary.crypto_box_open_easy(array2, cipherText, (long)cipherText.Length, nonce, publicKey, secretKey) != 0)
     {
         throw new CryptographicException("Failed to open PublicKeyBox");
     }
     return(array2);
 }