Beispiel #1
0
 def encrypt(self, data: bytes) -> bytes:
     """
     Encrypt data.
     :param data: plaintext data to encrypt.
     :return: encrypted data.
     """
     return rc4.crypt(self.key, data)
Beispiel #2
0
 def encrypt(self, data):
     """
     Encrypt data.
     :param data: plaintext data to encrypt.
     :type data: bytes
     :return: str
     """
     return rc4.crypt(self.key, data)
Beispiel #3
0
def updateKey(initialKey, currentKey, method):
    """
    Update a key.
    See: http://msdn.microsoft.com/en-us/library/cc240792.aspx
    :param initialKey: initial key.
    :type initialKey: bytes
    :param currentKey: current key.
    :type currentKey: bytes
    :param method: encryption method.
    :type method: EncryptionMethod
    :return: str
    """
    if method == EncryptionMethod.ENCRYPTION_40BIT:
        tempKey128 = tempKey(initialKey[:8], currentKey[:8])
        return gen40bits(rc4.crypt(rc4.RC4Key(tempKey128[:8]), tempKey128[:8]))
    elif method == EncryptionMethod.ENCRYPTION_56BIT:
        tempKey128 = tempKey(initialKey[:8], currentKey[:8])
        return gen56bits(rc4.crypt(rc4.RC4Key(tempKey128[:8]), tempKey128[:8]))
    elif method == EncryptionMethod.ENCRYPTION_128BIT:
        tempKey128 = tempKey(initialKey, currentKey)
        return rc4.crypt(rc4.RC4Key(tempKey128), tempKey128)