Esempio n. 1
0
func BoxOpenAfterNm(messageOut []byte, cypherText []byte, nonce, key []byte) int {
	checkSize(messageOut, len(cypherText), "message output")
	checkSize(nonce, BoxNonceBytes(), "nonce")
	checkSize(key, BoxBeforeNmBytes(), "key")

	return int(C.crypto_box_open_afternm(
		(*C.uchar)(&messageOut[0]),
		(*C.uchar)(&cypherText[0]), (C.ulonglong)(len(cypherText)),
		(*C.uchar)(&nonce[0]),
		(*C.uchar)(&key[0])))
}
func (b Boxer) Unbox(box []byte, nonce []byte) ([]byte, error) {
	result := make([]byte, C.crypto_box_BOXZEROBYTES+len(box))

	copy(result[C.crypto_box_BOXZEROBYTES:], box)

	code := C.crypto_box_open_afternm(array(result), array(result), C.ulonglong(len(result)), array(nonce), array(b))

	if code == 0 {
		return result[C.crypto_box_ZEROBYTES:], nil
	} else {
		return nil, ErrBoxOpen
	}
}