예제 #1
0
    def test_AsymCrypto_With_Seeded_Keypair(self):
        msg     = "correct horse battery staple"
        nonce   = pysodium.randombytes(pysodium.crypto_box_NONCEBYTES)
        pk, sk = pysodium.crypto_box_seed_keypair("howdy")

        c = pysodium.crypto_box_easy(msg, nonce, pk, sk)
        m = pysodium.crypto_box_open_easy(c, nonce, pk, sk)
        
        self.assertEqual(msg, m)
예제 #2
0
    def test_AsymCrypto_With_Seeded_Keypair(self):
        msg = "correct horse battery staple"
        nonce = pysodium.randombytes(pysodium.crypto_box_NONCEBYTES)
        pk, sk = pysodium.crypto_box_seed_keypair("howdy")

        c = pysodium.crypto_box_easy(msg, nonce, pk, sk)
        m = pysodium.crypto_box_open_easy(c, nonce, pk, sk)

        self.assertEqual(msg, m)
예제 #3
0
def decrypt(rsk, msg):
    """
    Decrypt a message using the provided information.
    """
    spk, nonce, enc_msg = msg.split(b':')

    spk = base64.b64decode(spk)
    rsk = base64.b64decode(rsk)
    nonce = base64.b64decode(nonce)
    enc_msg = base64.b64decode(enc_msg)

    # A ValueError is raised when decryption fails. Need to cactch it.
    try:
        dec_msg = pysodium.crypto_box_open_easy(enc_msg, nonce, spk, rsk)
    except ValueError:
        dec_msg = ''

    # Return the sender's public key and the decrypted message.
    return base64.b64encode(spk), dec_msg
예제 #4
0
파일: client.py 프로젝트: carriercomm/zkm
def decrypt(rsk, msg):
    """
    Decrypt a message using the provided information.
    """
    spk, nonce, enc_msg = msg.split(b':')

    spk = base64.b64decode(spk)
    rsk = base64.b64decode(rsk)
    nonce = base64.b64decode(nonce)
    enc_msg = base64.b64decode(enc_msg)

    # A ValueError is raised when decryption fails. Need to cactch it.
    try:
        dec_msg = pysodium.crypto_box_open_easy(enc_msg, nonce, spk, rsk)
    except ValueError:
        dec_msg = ''

    # Return the sender's public key and the decrypted message.
    return base64.b64encode(spk), dec_msg