コード例 #1
0
ファイル: keys.py プロジェクト: manojgop/avalon
    def __init__(self, verifying_key, encryption_key):
        """
        initialize the object

        :param verifying_key: PEM encoded ECDSA verifying key
        :param encryption_key: PEM encoded RSA encryption key
        """
        self._verifying_key = crypto.SIG_PublicKey(verifying_key)
        self._encryption_key = crypto.PKENC_PublicKey(encryption_key)
コード例 #2
0
def generate_encrypted_key(key, encryption_key):
    """
    Function to generate session key for the client
    Parameters:
    - encryption_key is a one-time encryption used to encrypt the passed key
    - key that needs to be encrypted
    """

    pub_enc_key = crypto.PKENC_PublicKey(encryption_key)
    return pub_enc_key.EncryptMessage(key)
コード例 #3
0
try:
    res = epk.VerifySignature(msg, bytes("invalid signature", 'ascii'))
except Exception as exc:
    logger.error("ERROR: Invalid signature detection test failed: ", exc)
    sys.exit(-1)
if (res != 1):
    logger.debug("Invalid signature detection test successful!")
else:
    logger.error("ERROR: Invalid signature detection test failed.")
    exit(-1)

# TEST RSA
try:
    rsk = crypto.PKENC_PrivateKey()
    rsk.Generate()
    rpk = crypto.PKENC_PublicKey(rsk)
except Exception as exc:
    logger.error(
        "ERROR: Asymmetric encryption Private and Public keys " +
        "generation test failed: ", exc)
    sys.exit(-1)
logger.debug("Asymmetric encryption Private and Public keys " +
             "generation test successful!")

try:
    rskString = rsk.Serialize()
    rpkString = rpk.Serialize()
    rsk1 = crypto.PKENC_PrivateKey(rskString)
    rpk1 = crypto.PKENC_PublicKey(rpkString)
    rskString1 = rsk1.Serialize()
    rpkString1 = rpk1.Serialize()