Beispiel #1
0
    def box_generate_keypair(self):
        key_pair_request = sodium.BoxKeyPairGenerateRequest()
        req = sodium.Request(boxKeyPairGenerateRequest=key_pair_request)
        res = self._send_request(req, 'box_generate_keypair')

        if res.HasField('error'):
            raise SodiumOperationError()

        return res.boxKeyPairGenerateResponse.keyPair.publicKey, res.boxKeyPairGenerateResponse.keyPair.secretKey
Beispiel #2
0
    def box_seal(self, plaintext, receiver_public_key):
        box_seal_request = sodium.BoxSealRequest(plaintext=plaintext,
                                                 publicKey=receiver_public_key)
        req = sodium.Request(boxSealRequest=box_seal_request)
        res = self._send_request(req, 'box_seal')

        if res.HasField('error'):
            raise SodiumOperationError()

        return res.boxSealResponse.ciphertext
Beispiel #3
0
    def hash_generic(self, msg):
        hashgeneric_request = sodium.HashGenericRequest(message=msg)

        req = sodium.Request(hashGenericRequest=hashgeneric_request)
        res = self._send_request(req, 'hash_generic')

        if res.HasField('error'):
            raise SodiumOperationError()

        return res.hashGenericResponse.signature
Beispiel #4
0
    def sign_generate_keypair(self):
        sign_keypair_request = sodium.SignKeyPairGenerateRequest()

        req = sodium.Request(signKeyPairGenerateRequest=sign_keypair_request)
        res = self._send_request(req, 'sign_generate_keypair')

        if res.HasField('error'):
            raise SodiumOperationError()

        return res.signKeyPairGenerateResponse.keyPair.publicKey, res.signKeyPairGenerateResponse.keyPair.secretKey
Beispiel #5
0
    def sign_detached(self, msg, sender_secret_key):
        sign_detached_request = sodium.SignDetachedRequest(
            message=msg, secretKey=sender_secret_key)

        req = sodium.Request(signDetachedRequest=sign_detached_request)
        res = self._send_request(req, 'sign_detached')

        if res.HasField('error'):
            raise SodiumOperationError()

        return res.signDetachedResponse.digest
Beispiel #6
0
    def box_easy(self, plaintext, sender_secret_key, receiver_public_key):
        box_easy_request = sodium.BoxEasyRequest(plaintext=plaintext,
                                                 secretKey=sender_secret_key,
                                                 publicKey=receiver_public_key)
        req = sodium.Request(boxEasyRequest=box_easy_request)
        res = self._send_request(req, 'box_easy')

        if res.HasField('error'):
            raise SodiumOperationError()

        return res.boxEasyResponse.ciphertext, res.boxEasyResponse.nonce
Beispiel #7
0
    def sign_detached_verify(self, msg, signature, sender_public_key):
        sign_detached_verify_request = sodium.SignDetachedVerifyRequest(
            message=msg, signature=signature, publicKey=sender_public_key)

        req = sodium.Request(
            signDetachedVerifyRequest=sign_detached_verify_request)
        res = self._send_request(req, 'sign_detached_verify')

        if res.HasField('error'):
            raise SodiumOperationError()

        return res.signDetachedVerifyResponse.signatureMatches
Beispiel #8
0
    def box_seal_open(self, ciphertext, self_public_key, self_secret_key):
        box_seal_open_request = sodium.BoxSealOpenRequest(
            ciphertext=ciphertext,
            keypair=sodium.KeyPair(publicKey=self_public_key,
                                   secretKey=self_secret_key))

        req = sodium.Request(boxSealOpenRequest=box_seal_open_request)
        res = self._send_request(req, 'box_seal_open')

        if res.HasField('error'):
            raise SodiumOperationError()

        return res.boxSealOpenResponse.plaintext
Beispiel #9
0
    def box_easy_open(self, ciphertext, nonce, sender_public_key,
                      receiver_secret_key):
        box_easy_open_request = sodium.BoxEasyOpenRequest(
            ciphertext=ciphertext,
            nonce=nonce,
            publicKey=sender_public_key,
            secretKey=receiver_secret_key)

        req = sodium.Request(boxEasyOpenRequest=box_easy_open_request)
        res = self._send_request(req, 'box_easy_open')

        if res.HasField('error'):
            raise SodiumOperationError()

        return res.boxEasyOpenResponse.plaintext