python类get_random_bytes()的实例源码

Wallet.py 文件源码 项目:neo-python 作者: CityOfZion 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def CreateKey(self, private_key=None):
        """
        Create a KeyPair

        Args:
            private_key (iterable_of_ints): (optional) 32 byte private key

        Returns:
            KeyPair: a KeyPair instance
        """
        if private_key is None:
            private_key = bytes(Random.get_random_bytes(32))

        key = KeyPair(priv_key=private_key)
        self._keys[key.PublicKeyHash.ToBytes()] = key
        return key
Encryption.py 文件源码 项目:cottoncandy 作者: gallantlab 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def generate_AES_key(self, key_size=None):
        """Generates a new AES key

        Parameters
        ----------
        key_size : int
            bits in key

        Returns
        -------
        key : str
            AES key
        """
        if key_size is None:
            key_size = self.AES_key_length
        if key_size not in [16, 24, 32]:
            raise ValueError('Bad AES key size')
        return Random.get_random_bytes(key_size)
options.py 文件源码 项目:cottoncandy 作者: gallantlab 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def generate_AES_key(bytes = 32):
    """Generates a new AES key

    Parameters
    ----------
    bytes : int
        number of bytes in key

    Returns
    -------
    key : bytes
    """
    try:
        from Crypto import Random
        return Random.get_random_bytes(bytes)
    except ImportError:
        print('PyCrypto not install. Reading from /dev/random instead')
        with open('/dev/random', 'r') as rand:
            return rand.read(bytes)
ransomware.py 文件源码 项目:ransomware 作者: xiaozhouas 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def encryptFile(in_filename, out_filename=None, chunksize=64*1024):
    if not out_filename:
        out_filename = in_filename + '.enc'

    key = Random.get_random_bytes(32)
    iv = Random.get_random_bytes(16)
    encryptor = AES.new(key, AES.MODE_CBC, iv)
    #filesize = os.path.getsize(in_filename)

    with open(in_filename, 'rb') as infile:
        with open(out_filename, 'wb') as outfile:
            #outfile.write(struct.pack('<Q', filesize))
            outfile.write(key)
            outfile.write(iv)
            while True:
                chunk = infile.read(chunksize)
                if len(chunk) == 0:
                    break
                elif len(chunk) % 16 != 0:
                    chunk += b' ' * (16 - len(chunk) % 16)

                outfile.write(encryptor.encrypt(chunk))
            os.remove(in_filename)
vis_encrypt.py 文件源码 项目:PACE-python 作者: mit-ll 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _encrypt_with_shares(cls, plaintext, key_id, vis_expr):
        '''
        Arguments:
        plaintext - plaintext portion of the cell to be encrypted
        key_id - the keytor object,contains a key_id and handle on the key_objection 
              to obtain the keys.
        vis_expr - visibility expression of the cell to be encrypted

        Returns - the encrypted shares concatenated with the ciphertext
        or the field of the cell being encrypted 
        '''
        #generate a random key for the cell 
        cell_key = Random.get_random_bytes(key_id.cell_key_length)
        #break into shares and then encrypt
        encrypted_shares = SecretVisTreeEncryptor.encrypt_secret_shares(vis_expr,
                                                                 cell_key,
                                                                 key_id,
                                                                 cls.leaf_class)
        #encrypt the plaintext 
        ciphertext = cls._encrypt(plaintext, cell_key)
        return encrypted_shares + "#" + ciphertext
file.py 文件源码 项目:keyrings.alt 作者: jaraco 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def encrypt(self, password, assoc = None):
        # encrypt password, ignore associated data
        from Crypto.Random import get_random_bytes
        salt = get_random_bytes(self.block_size)
        from Crypto.Cipher import AES
        IV = get_random_bytes(AES.block_size)
        cipher = self._create_cipher(self.keyring_key, salt, IV)
        password_encrypted = cipher.encrypt(self.pw_prefix + password)
        # Serialize the salt, IV, and encrypted password in a secure format
        data = dict(
            salt=salt, IV=IV, password_encrypted=password_encrypted,
        )
        for key in data:
            # spare a few bytes: throw away newline from base64 encoding
            data[key] = encodebytes(data[key]).decode()[:-1]
        return json.dumps(data).encode()
common.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
ipsec.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def generate_iv(self):
        """
        Generate a random initialization vector. If pycrypto is not available,
        return a buffer of the correct length filled with only '\x00'.
        """
        if Random:
            return Random.get_random_bytes(self.iv_size)
        else:
            return chr(0) * self.iv_size
common.py 文件源码 项目:watchmen 作者: lycclsltt 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
common.py 文件源码 项目:aws-cfn-plex 作者: lordmuffin 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
common.py 文件源码 项目:git_intgrtn_aws_s3 作者: droidlabour 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
common.py 文件源码 项目:MCSManager-fsmodule 作者: Suwings 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
test-authenticate.py 文件源码 项目:PyKI 作者: pykiki 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def authBykey(pubkeydir, privkeyString, passph):
    # encrypt with pubkey
    if pubkeydir[-1] != '/':
        pubkeydir = pubkeydir + "/"

    try:
        pkey = open(pubkeydir + "public_key.pem", "rt")
        public_key = RSA.importKey(pkey.read())
        pkey.close()
    except FileNotFoundError as e:
        res = {"error": True, "message": 'ERROR: Public key not found.'}
        return(res)
    except:
        res = {"error": True, "message": 'ERROR: Problem reading public key'}
        return(res)

    randomData = Random.get_random_bytes(32)
    enc_data = public_key.encrypt(b'success', randomData)

    # decrypt with private key
    private_key = RSA.importKey(privkeyString, passph)
    dec_data = private_key.decrypt(enc_data)
    if dec_data == b'success':
        # self.__token = SHA256.new(private_key.exportKey()).digest()
        res = {"error": False, "message": "INFO: Successfully authenticated"}
        return(res)
    else:
        res = {"error": True, "message": 'ERROR: Unable to authenticate'}
        return(res)
ipsec.py 文件源码 项目:trex-http-proxy 作者: alwye 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def generate_iv(self):
        """
        Generate a random initialization vector. If pycrypto is not available,
        return a buffer of the correct length filled with only '\x00'.
        """
        if Random:
            return Random.get_random_bytes(self.iv_size)
        else:
            return chr(0) * self.iv_size
ipsec.py 文件源码 项目:trex-http-proxy 作者: alwye 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def generate_iv(self):
        """
        Generate a random initialization vector. If pycrypto is not available,
        return a buffer of the correct length filled with only '\x00'.
        """
        if Random:
            return Random.get_random_bytes(self.iv_size)
        else:
            return chr(0) * self.iv_size
common.py 文件源码 项目:PyMal 作者: cysinfo 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
Encryption.py 文件源码 项目:cottoncandy 作者: gallantlab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def generate_key(self, key_size=32):
        """Generates a new AES key

        Parameters
        ----------
        key_size : int
            bits in key

        Returns
        -------

        """
        if key_size not in [16, 24, 32]:
            raise RuntimeError('Bad key length')
        self.key = Random.get_random_bytes(key_size)
common.py 文件源码 项目:SublimeRemoteGDB 作者: summerwinter 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
ipsec.py 文件源码 项目:scapy-bpf 作者: guedou 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def generate_iv(self):
        """
        Generate a random initialization vector. If pycrypto is not available,
        return a buffer of the correct length filled with only '\x00'.
        """
        if Random:
            return Random.get_random_bytes(self.iv_size)
        else:
            return chr(0) * self.iv_size
common.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
ipsec.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def generate_iv(self):
        """
        Generate a random initialization vector. If pycrypto is not available,
        return a buffer of the correct length filled with only '\x00'.
        """
        if Random:
            return Random.get_random_bytes(self.iv_size)
        else:
            return chr(0) * self.iv_size
common.py 文件源码 项目:Encryped-file-system 作者: kittenish 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
ipsec.py 文件源码 项目:scapy-radio 作者: BastilleResearch 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def generate_iv(self):
        """
        Generate a random initialization vector. If pycrypto is not available,
        return a buffer of the correct length filled with only '\x00'.
        """
        if Random:
            return Random.get_random_bytes(self.iv_size)
        else:
            return chr(0) * self.iv_size
fields.py 文件源码 项目:Quiver-alfred 作者: danielecook 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def encrypt(self, value):
            iv = Random.get_random_bytes(AES.block_size)
            cipher = self.get_cipher(self.key, iv)
            return iv + cipher.encrypt(value)
common.py 文件源码 项目:isf 作者: w3h 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
ipsec.py 文件源码 项目:isf 作者: w3h 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def generate_iv(self):
        """
        Generate a random initialization vector. If pycrypto is not available,
        return a buffer of the correct length filled with only '\x00'.
        """
        if Random:
            return Random.get_random_bytes(self.iv_size)
        else:
            return chr(0) * self.iv_size
common.py 文件源码 项目:kekescan 作者: xiaoxiaoleo 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
common.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, module, params):
        from Crypto import Random
        unittest.TestCase.__init__(self)
        self.module = module
        self.iv = Random.get_random_bytes(module.block_size)
        self.key = b(params['key'])
        self.plaintext = 100 * b(params['plaintext'])
        self.module_name = params.get('module_name', None)
fields.py 文件源码 项目:metrics 作者: Jeremy-Friedman 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def encrypt(self, value):
            iv = Random.get_random_bytes(AES.block_size)
            cipher = self.get_cipher(self.key, iv)
            return iv + cipher.encrypt(value)
fields.py 文件源码 项目:metrics 作者: Jeremy-Friedman 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def encrypt(self, value):
            iv = Random.get_random_bytes(AES.block_size)
            cipher = self.get_cipher(self.key, iv)
            return iv + cipher.encrypt(value)


问题


面经


文章

微信
公众号

扫码关注公众号