Return SigningKey instance from Duniter WIF or EWIF file

        :param path: Path to WIF of EWIF file
        :param password: Password needed for EWIF file
517478
def from_wif_or_ewif_file(path: str, password: Optional[str] = None) -> SigningKeyType:
        
        with open(path, 'r') as fh:
            wif_content = fh.read()

        # check data field
        regex = compile('Data: ([1-9A-HJ-NP-Za-km-z]+)', MULTILINE)
        match = search(regex, wif_content)
        if not match:
            raise Exception('Error: Bad format WIF or EWIF v1 file')

        # capture hexa wif key
        wif_hex = match.groups()[0]
        return SigningKey.from_wif_or_ewif_hex(wif_hex, password)
35208
def load_key(self, key_path, password):
        

        try:
            return paramiko.RSAKey.from_private_key_file(key_path)
        except PasswordRequiredException as ex:
            return paramiko.RSAKey.from_private_key_file(key_path,
                                                         password=password)
1252910
def get_key_auth_cb(key_filepath):
    """"""

    def auth_cb(ssh):
        key = ssh_pki_import_privkey_file(key_filepath)
        ssh.userauth_publickey(key)

    return auth_cb
1240080
def cmd_signing_setup(self, args):
        ''''''
        if len(args) == 0:
            print("usage: signing setup passphrase")
            return
        if not self.master.mavlink20():
            print("You must be using MAVLink2 for signing")
            return
        passphrase = args[0]
        key = self.passphrase_to_key(passphrase)
        secret_key = []
        for b in key:
            secret_key.append(ord(b))

        epoch_offset = 1420070400
        now = max(time.time(), epoch_offset)
        initial_timestamp = int((now - epoch_offset)*1e5)
        self.master.mav.setup_signing_send(self.target_system, self.target_component,
                                           secret_key, initial_timestamp)
        print("Sent secret_key")
        self.cmd_signing_key([passphrase])
1201311
def wif_to_privkey(wif, compressed=True, net=BC):
    """"""
    key = b58decode(wif)

    version, raw, check = key[0:1], key[1:-4], key[-4:]
    assert version == net.wifprefix, "unexpected version byte"

    check_compare = shasha(version + raw).digest()[:4]
    assert check_compare == check

    if compressed:
        raw = raw[:-1]

    return raw
694415
public static PrivateKey getSignCertPrivateKeyByStoreMap(String certPath,
			String certPwd) {
		if (!keyStoreMap.containsKey(certPath)) {
			loadSignCert(certPath, certPwd);
		}
		try {
			Enumeration<String> aliasenum = keyStoreMap.get(certPath)
					.aliases();
			String keyAlias = null;
			if (aliasenum.hasMoreElements()) {
				keyAlias = aliasenum.nextElement();
			}
			PrivateKey privateKey = (PrivateKey) keyStoreMap.get(certPath)
					.getKey(keyAlias, certPwd.toCharArray());
			return privateKey;
		} catch (KeyStoreException e) {
			LogUtil.writeErrorLog("getSignCertPrivateKeyByStoreMap Error", e);
			return null;
		} catch (UnrecoverableKeyException e) {
			LogUtil.writeErrorLog("getSignCertPrivateKeyByStoreMap Error", e);
			return null;
		} catch (NoSuchAlgorithmException e) {
			LogUtil.writeErrorLog("getSignCertPrivateKeyByStoreMap Error", e);
			return null;
		}
	}
571560
def generate_key(filepath):
    ''' 
    '''
    fs = path.abspath(path.expanduser(filepath))
    with open(fs, 'wb') as outfile:
        outfile.write(Fernet.generate_key())
    chmod(fs, 0o400)
    return fs
1235175
def export_wif(self) -> str:
        
        data = b''.join([b'\x80', self.__private_key, b'\01'])
        checksum = Digest.hash256(data[0:34])
        wif = base58.b58encode(b''.join([data, checksum[0:4]]))
        return wif.decode('ascii')
933009
def load(cls, path: str, password: str = None) -> 'Account':
        
        with open(path) as f:
            keystore = json.load(f)
        if not check_keystore_json(keystore):
            raise ValueError('Invalid keystore file')
        return Account(keystore, password, path=path)
762131
def get(self, sid):
        
        return SigningKeyContext(self._version, account_sid=self._solution['account_sid'], sid=sid, )
1154430
def sign(self, key, network_id=None):
        
        if network_id is None:
            rawhash = utils.sha3(rlp.encode(unsigned_tx_from_tx(self), UnsignedTransaction))
        else:
            assert 1 <= network_id < 2**63 - 18
            rlpdata = rlp.encode(rlp.infer_sedes(self).serialize(self)[
                                 :-3] + [network_id, b'', b''])
            rawhash = utils.sha3(rlpdata)

        key = normalize_key(key)

        v, r, s = ecsign(rawhash, key)
        if network_id is not None:
            v += 8 + network_id * 2

        ret = self.copy(
            v=v, r=r, s=s
        )
        ret._sender = utils.privtoaddr(key)
        return ret
1135079
def decrypt(self, passphrase, wif=False):
        
        passphrase = normalize('NFC', unicode(passphrase))
        if is_py2:
            passphrase = passphrase.encode('utf8')

        if self.ec_multiply:
            raise Exception("Not supported yet")

        key = scrypt.hash(passphrase, self.addresshash, 16384, 8, 8)
        derivedhalf1 = key[0:32]
        derivedhalf2 = key[32:64]

        aes = AES.new(derivedhalf2)
        decryptedhalf2 = aes.decrypt(self.encryptedhalf2)
        decryptedhalf1 = aes.decrypt(self.encryptedhalf1)
        priv = decryptedhalf1 + decryptedhalf2
        priv = unhexlify('%064x' % (long(hexlify(priv), 16) ^ long(hexlify(derivedhalf1), 16)))
        pub = privtopub(priv)

        if self.compressed:
            pub = encode_pubkey(pub, 'hex_compressed')
        addr = pubtoaddr(pub, self.pub_byte)

        if is_py2:
            ascii_key = addr
        else:
            ascii_key = bytes(addr,'ascii')

        if sha256(sha256(ascii_key).digest()).digest()[0:4] != self.addresshash:
            raise Exception('Bip38 password decrypt failed: Wrong password?')
        else:
            formatt = 'wif' if wif else 'hex'
            if self.compressed:
                return encode_privkey(priv, formatt + '_compressed', self.priv_byte)
            else:
                return encode_privkey(priv, formatt, self.priv_byte)
1358757
def get_encrpyted_path(original_path, surfix=default_surfix):
    
    p = Path(original_path).absolute()
    encrypted_p = p.change(new_fname=p.fname + surfix)
    return encrypted_p.abspath
250485
def get_drive_api_from_file(path):
    
    f = open(path)
    credentials = client.OAuth2Credentials.from_json(f.read())
    return _get_drive_api(credentials)
858151
def gen_signature(priv_path, pub_path, sign_path, passphrase=None):
    '''
    
    '''

    with salt.utils.files.fopen(pub_path) as fp_:
        mpub_64 = fp_.read()

    mpub_sig = sign_message(priv_path, mpub_64, passphrase)
    mpub_sig_64 = binascii.b2a_base64(mpub_sig)
    if os.path.isfile(sign_path):
        return False
    log.trace(
        'Calculating signature for %s with %s',
        os.path.basename(pub_path), os.path.basename(priv_path)
    )

    if os.path.isfile(sign_path):
        log.trace(
            'Signature file %s already exists, please remove it first and '
            'try again', sign_path
        )
    else:
        with salt.utils.files.fopen(sign_path, 'wb+') as sig_f:
            sig_f.write(salt.utils.stringutils.to_bytes(mpub_sig_64))
        log.trace('Wrote signature to %s', sign_path)
    return True
776093
def from_credentials(cls: Type[SigningKeyType], salt: Union[str, bytes], password: Union[str, bytes],
                         scrypt_params: Optional[ScryptParams] = None) -> SigningKeyType:
        
        if scrypt_params is None:
            scrypt_params = ScryptParams()

        salt = ensure_bytes(salt)
        password = ensure_bytes(password)
        seed = scrypt(password, salt, scrypt_params.N, scrypt_params.r, scrypt_params.p, scrypt_params.seed_length)

        return cls(seed)
960670
def PrivateKeyFromWIF(wif):
        
        if wif is None or len(wif) is not 52:
            raise ValueError('Please provide a wif with a length of 52 bytes (LEN: {0:d})'.format(len(wif)))

        data = base58.b58decode(wif)

        length = len(data)

        if length is not 38 or data[0] is not 0x80 or data[33] is not 0x01:
            raise ValueError("Invalid format!")

        checksum = Crypto.Hash256(data[0:34])[0:4]

        if checksum != data[34:]:
            raise ValueError("Invalid WIF Checksum!")

        return data[1:33]