示例#1
0
// SecretBoxOpen opens the authenticated cypher text produced by SecretBox and returns the original
// message plain text. The cypher text is authenticated prior to decryption to ensure it has not
// been modified from the original. The messageOut buffer must be the same size as the cypherText
// buffer and will be padded with SecretBoxZeroBytes() worth of leading zero bytes.
//
// Returns: 0 on success, non-zero on failure
func SecretBoxOpen(messageOut, cypherText, nonce, key []byte) int {
	checkSize(messageOut, len(cypherText), "message output")
	checkSize(nonce, SecretBoxNonceBytes(), "nonce")
	checkSize(key, SecretBoxKeyBytes(), "key")

	return int(C.crypto_secretbox_open(
		(*C.uchar)(&messageOut[0]),
		(*C.uchar)(&cypherText[0]), (C.ulonglong)(len(cypherText)),
		(*C.uchar)(&nonce[0]),
		(*C.uchar)(&key[0])))
}
示例#2
0
func CryptoSecretBoxOpen(c []byte, n []byte, k []byte) ([]byte, int) {
	support.CheckSize(n, CryptoSecretBoxNonceBytes(), "nonce")
	support.CheckSize(k, CryptoSecretBoxKeyBytes(), "key")
	m := make([]byte, len(c)-CryptoSecretBoxMacBytes())
	exit := int(C.crypto_secretbox_open(
		(*C.uchar)(&m[0]),
		(*C.uchar)(&c[0]),
		(C.ulonglong)(len(c)),
		(*C.uchar)(&n[0]),
		(*C.uchar)(&k[0])))

	return m, exit
}