Parse an electrum public key from a text string in seed form ("E:xxx" where xxx
        is a 128-character hex string).
        Return a :class:`ElectrumWallet <pycoin.key.electrum.ElectrumWallet>` or None.
354876
def electrum_pub(self, s):
        
        blob = self._electrum_to_blob(s)
        if blob and len(blob) == 64:
            return self._network.keys.electrum_public(master_public_key=blob)
341096
def tokhex(length=10, urlsafe=False):
    
    if urlsafe is True:
        return secrets.token_urlsafe(length)
    return secrets.token_hex(length)
805765
def read_serialized_rsa_pub_key(serialized):
        
        n = None
        e = None
        rsa = from_hex(serialized)

        pos = 0
        ln = len(rsa)
        while pos < ln:
            tag = bytes_to_byte(rsa, pos)
            pos += 1
            length = bytes_to_short(rsa, pos)
            pos += 2

            if tag == 0x81:
                e = bytes_to_long(rsa[pos:pos+length])
            elif tag == 0x82:
                n = bytes_to_long(rsa[pos:pos+length])

            pos += length

        if e is None or n is None:
            logger.warning("Could not process import key")
            raise ValueError('Public key deserialization failed')

        return n, e
835788
def uuid_from_string(string)
      hash = Digest::SHA1.new
      hash.update(string)
      ary = hash.digest.unpack('NnnnnN')
      ary[2] = (ary[2] & 0x0FFF) | (5 << 12)
      ary[3] = (ary[3] & 0x3FFF) | 0x8000
      # rubocop:disable Style/FormatString
      '%08x-%04x-%04x-%04x-%04x%08x' % ary
    end
1033780
def to_point
      p = pubkey
      p ||= generate_pubkey(priv_key, compressed: compressed)
      ECDSA::Format::PointOctetString.decode(p.htb, Bitcoin::Secp256k1::GROUP)
    end
1332353
def parse_from_string(
        root_processor,  # type: RootProcessor
        xml_string  # type: Text
):
    # type: (...) -> Any
    
    if not _is_valid_root_processor(root_processor):
        raise InvalidRootProcessor('Invalid root processor')

    parseable_xml_string = xml_string  # type: Union[Text, bytes]
    if _PY2 and isinstance(xml_string, Text):
        parseable_xml_string = xml_string.encode('utf-8')

    root = ET.fromstring(parseable_xml_string)
    _xml_namespace_strip(root)

    state = _ProcessorState()
    state.push_location(root_processor.element_path)
    return root_processor.parse_at_root(root, state)
69627
def decrypt(aes_key, text, corpid)
      status = 200
      text        = Base64.decode64(text)
      text        = handle_cipher(:decrypt, aes_key, text)
      result      = PKCS7Encoder.decode(text)
      content     = result[16...result.length]
      len_list    = content[0...4].unpack("N")
      xml_len     = len_list[0]
      xml_content = content[4...4 + xml_len]
      from_corpid = content[xml_len+4...content.size]
      # TODO: refactor
      if corpid != from_corpid
        Rails.logger.debug("#{__FILE__}:#{__LINE__} Failure because #{corpid} != #{from_corpid}")
        status = 401
      end
      [xml_content, status]
    end
950145
private PublicKey getPemPublicKey(final String keyString) throws EncryptionException {
      try {
         final String publicKeyPEM = keyString.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").replaceAll("\\v", "");

         final Base64 b64 = new Base64();
         final byte[] decoded = b64.decode(publicKeyPEM);

         final X509EncodedKeySpec spec = new X509EncodedKeySpec(decoded);
         final KeyFactory kf = KeyFactory.getInstance(ALGORITHM);

         return kf.generatePublic(spec);
      } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
         throw new EncryptionException("Unable to obtain public key: ", e);
      }
   }
1145475
def parse_pubkey(blob):
    
    fp = fingerprint(blob)
    s = io.BytesIO(blob)
    key_type = util.read_frame(s)
    log.debug('key type: %s', key_type)
    assert key_type in SUPPORTED_KEY_TYPES, key_type

    result = {'blob': blob, 'type': key_type, 'fingerprint': fp}

    if key_type == SSH_NIST256_KEY_TYPE:
        curve_name = util.read_frame(s)
        log.debug('curve name: %s', curve_name)
        point = util.read_frame(s)
        assert s.read() == b''
        _type, point = point[:1], point[1:]
        assert _type == SSH_NIST256_DER_OCTET
        size = len(point) // 2
        assert len(point) == 2 * size
        coords = (util.bytes2num(point[:size]), util.bytes2num(point[size:]))

        curve = ecdsa.NIST256p
        point = ecdsa.ellipticcurve.Point(curve.curve, *coords)

        def ecdsa_verifier(sig, msg):
            assert len(sig) == 2 * size
            sig_decode = ecdsa.util.sigdecode_string
            vk = ecdsa.VerifyingKey.from_public_point(point, curve, hashfunc)
            vk.verify(signature=sig, data=msg, sigdecode=sig_decode)
            parts = [sig[:size], sig[size:]]
            return b''.join([util.frame(b'\x00' + p) for p in parts])

        result.update(point=coords, curve=CURVE_NIST256,
                      verifier=ecdsa_verifier)

    if key_type == SSH_ED25519_KEY_TYPE:
        pubkey = util.read_frame(s)
        assert s.read() == b''

        def ed25519_verify(sig, msg):
            assert len(sig) == 64
            vk = ed25519.VerifyingKey(pubkey)
            vk.verify(sig, msg)
            return sig

        result.update(curve=CURVE_ED25519, verifier=ed25519_verify)

    return result
453706
function getPubkeyHex(privkey_hex) {
   let privkey = BigInteger.fromBuffer( decodePrivateKey(privkey_hex) );
   let public_key = new bitcoinjs.ECPair(privkey);

   public_key.compressed = false;
   let public_key_str = public_key.getPublicKeyBuffer().toString('hex');
   return public_key_str;
}
1323537
def ecdsa_public_key(pubkey_str, compressed=None):
    
    if compressed == True:
        pubkey_str = keylib.key_formatting.compress(pubkey_str)
    elif compressed == False:
        pubkey_str = keylib.key_formatting.decompress(pubkey_str)

    return _ECPublicKey(pubkey_str)
269582
def decrypt_text(self, text, *args, **kwargs):
        
        b = text.encode("utf-8")
        token = base64.b64decode(b)
        return self.decrypt(token, *args, **kwargs).decode("utf-8")
1249112
def hexlify_pbkdf2(password, salt, iterations, length, digest=hashlib.sha1):
    
    # log.debug("hexlify_pbkdf2 with iterations=%i", iterations)
    hash = crypto.pbkdf2(password, salt, iterations=iterations, dklen=length, digest=digest)
    hash = binascii.hexlify(hash)
    hash = six.text_type(hash, "ascii")
    return hash
223949
def parse_PRIK(chunk, encryption_key):
    """"""
    decrypted = decode_aes256('cbc',
                              encryption_key[:16],
                              decode_hex(chunk.payload),
                              encryption_key)

    hex_key = re.match(br'^LastPassPrivateKey<(?P<hex_key>.*)>LastPassPrivateKey$', decrypted).group('hex_key')
    rsa_key = RSA.importKey(decode_hex(hex_key))

    rsa_key.dmp1 = rsa_key.d % (rsa_key.p - 1)
    rsa_key.dmq1 = rsa_key.d % (rsa_key.q - 1)
    rsa_key.iqmp = number.inverse(rsa_key.q, rsa_key.p)

    return rsa_key
1220689
def client_seed(a=random.randrange(0, 1 << SRP_KEY_SIZE)):
    
    if DEBUG:
        a = DEBUG_PRIVATE_KEY
    N, g, k = get_prime()
    A = pow(g, a, N)
    if DEBUG_PRINT:
        print('a=', binascii.b2a_hex(long2bytes(a)), end='\n')
        print('A=', binascii.b2a_hex(long2bytes(A)), end='\n')
    return A, a
764227
def sec_to_public_pair(pubkey):
    """"""
    x = string_to_number(pubkey[1:33])
    sec0 = pubkey[:1]
    if sec0 not in (b'\2', b'\3'):
        raise Exception("Compressed pubkey expected")

    def public_pair_for_x(generator, x, is_even):
        curve = generator.curve()
        p = curve.p()
        alpha = (pow(x, 3, p) + curve.a() * x + curve.b()) % p
        beta = ecdsa.numbertheory.square_root_mod_prime(alpha, p)
        if is_even == bool(beta & 1):
            return (x, p - beta)
        return (x, beta)

    return public_pair_for_x(ecdsa.ecdsa.generator_secp256k1, x, is_even=(sec0 == b'\2'))
690179
def decode_ack_plain(ciphertext)
      message = begin
                  @ecc.ecies_decrypt ciphertext[0,210]
                rescue
                  raise AuthenticationError, $!
                end
      raise RLPxSessionError, 'invalid message length' unless message.size == 64+32+1

      ephemeral_pubkey = message[0,64]
      nonce = message[64,32]
      known = message[-1].ord
      raise RLPxSessionError, 'invalid known byte' unless known == 0

      [210, ephemeral_pubkey, nonce, 4]
    end