/// <summary> /// Encryptes input with secret box. /// </summary> public static byte[] SecretBox(byte[] Input, byte[] Nonce, byte[] SecretKey) { byte[] C = new byte[Input.Length + 32]; Array.Copy(Input, 0, C, 32, Input.Length); Xsalsa20Poly1305.CryptoSecretbox(C, C, C.Length, Nonce, SecretKey); byte[] Output = new byte[C.Length - 16]; Array.Copy(C, 16, Output, 0, Output.Length); return(Output); }
/// <summary> /// Decyptes input with secret box. /// </summary> public static byte[] SecretBoxOpen(byte[] Input, byte[] Nonce, byte[] SecretKey) { if (Input.Length >= 16) { byte[] C = new byte[Input.Length + 16]; Array.Copy(Input, 0, C, 16, Input.Length); if (Xsalsa20Poly1305.CryptoSecretboxOpen(C, C, C.Length, Nonce, SecretKey) == 0) { byte[] Output = new byte[C.Length - 32]; Array.Copy(C, 32, Output, 0, Output.Length); return(Output); } } Logging.Warning(typeof(PepperCrypto), "Unable to open secret box."); return(null); }