當前位置: 首頁>>代碼示例>>Python>>正文


Python crypto.sign方法代碼示例

本文整理匯總了Python中OpenSSL.crypto.sign方法的典型用法代碼示例。如果您正苦於以下問題:Python crypto.sign方法的具體用法?Python crypto.sign怎麽用?Python crypto.sign使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OpenSSL.crypto的用法示例。


在下文中一共展示了crypto.sign方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _sign

# 需要導入模塊: from OpenSSL import crypto [as 別名]
# 或者: from OpenSSL.crypto import sign [as 別名]
def _sign(private_key, data, digest=SHA256):
    '''
    An internal helper method to sign the 'data' with the 'private_key'.

    @type  private_key: C{str}
    @param private_key: The private key used to sign the 'data', in one of
                        supported formats.
    @type         data: C{str}
    @param        data: The data that needs to be signed.
    @type       digest: C{str}
    @param      digest: Digest is a str naming a supported message digest type,
                        for example 'sha256'.

    @rtype: C{str}
    @return: Signed string.
    '''
    # Convert private key in arbitrary format into DER (DER is binary format
    # so we get rid of \n / \r\n differences, and line breaks in PEM).
    pkey = _load_private_key(_extract_certificate(private_key))
    return base64.b64encode(crypto.sign(pkey, data, digest)) 
開發者ID:vmware,項目名稱:vsphere-automation-sdk-python,代碼行數:22,代碼來源:sso.py

示例2: _x509Prep

# 需要導入模塊: from OpenSSL import crypto [as 別名]
# 或者: from OpenSSL.crypto import sign [as 別名]
def _x509Prep(self, rootApi, req, data):
        if rootApi._x509Key is None:
            return
        payload = '{}{}'.format(req.method, req.url.replace(rootApi._url, ''))
        payload = unquote(payload)
        if data is not None:
            payload += data
        signature = base64.b64encode(sign(rootApi._x509Key, payload,
                                          'sha256'))
        if sys.version_info[0] >= 3:
            signature = signature.decode('ascii')

        cookie = ('APIC-Request-Signature={}; '
                  'APIC-Certificate-Algorithm=v1.0; '
                  'APIC-Certificate-Fingerprint=fingerprint; '
                  'APIC-Certificate-DN={}').format(
                      signature, rootApi._x509Dn)
        req.headers['Cookie'] = cookie 
開發者ID:datacenter,項目名稱:pyaci,代碼行數:20,代碼來源:core.py

示例3: __init__

# 需要導入模塊: from OpenSSL import crypto [as 別名]
# 或者: from OpenSSL.crypto import sign [as 別名]
def __init__(self, pkey):
      """Constructor.

      Args:
        pkey, OpenSSL.crypto.PKey (or equiv), The private key to sign with.
      """
      self._key = pkey 
開發者ID:mortcanty,項目名稱:earthengine,代碼行數:9,代碼來源:crypt.py

示例4: sign

# 需要導入模塊: from OpenSSL import crypto [as 別名]
# 或者: from OpenSSL.crypto import sign [as 別名]
def sign(self, message):
      """Signs a message.

      Args:
        message: string, Message to be signed.

      Returns:
        string, The signature of the message for the given key.
      """
      return crypto.sign(self._key, message, 'sha256') 
開發者ID:mortcanty,項目名稱:earthengine,代碼行數:12,代碼來源:crypt.py

示例5: make_signed_jwt

# 需要導入模塊: from OpenSSL import crypto [as 別名]
# 或者: from OpenSSL.crypto import sign [as 別名]
def make_signed_jwt(signer, payload):
  """Make a signed JWT.

  See http://self-issued.info/docs/draft-jones-json-web-token.html.

  Args:
    signer: crypt.Signer, Cryptographic signer.
    payload: dict, Dictionary of data to convert to JSON and then sign.

  Returns:
    string, The JWT for the payload.
  """
  header = {'typ': 'JWT', 'alg': 'RS256'}

  segments = [
      _urlsafe_b64encode(_json_encode(header)),
      _urlsafe_b64encode(_json_encode(payload)),
  ]
  signing_input = '.'.join(segments)

  signature = signer.sign(signing_input)
  segments.append(_urlsafe_b64encode(signature))

  logger.debug(str(segments))

  return '.'.join(segments) 
開發者ID:mortcanty,項目名稱:earthengine,代碼行數:28,代碼來源:crypt.py

示例6: make_signed_jwt

# 需要導入模塊: from OpenSSL import crypto [as 別名]
# 或者: from OpenSSL.crypto import sign [as 別名]
def make_signed_jwt(signer, payload):
  """Make a signed JWT.

  See http://self-issued.info/docs/draft-jones-json-web-token.html.

  Args:
    signer: crypt.Signer, Cryptographic signer.
    payload: dict, Dictionary of data to convert to JSON and then sign.

  Returns:
    string, The JWT for the payload.
  """
  header = {'typ': 'JWT', 'alg': 'RS256'}

  segments = [
          _urlsafe_b64encode(_json_encode(header)),
          _urlsafe_b64encode(_json_encode(payload)),
  ]
  signing_input = '.'.join(segments)

  signature = signer.sign(signing_input)
  segments.append(_urlsafe_b64encode(signature))

  logger.debug(str(segments))

  return '.'.join(segments) 
開發者ID:splunk,項目名稱:splunk-ref-pas-code,代碼行數:28,代碼來源:crypt.py

示例7: _sign

# 需要導入模塊: from OpenSSL import crypto [as 別名]
# 或者: from OpenSSL.crypto import sign [as 別名]
def _sign(self, content, digest='SHA256'):
        pkey = self.connector.p12.get_privatekey()

        return crypto.sign(pkey=pkey, data=content, digest=digest) 
開發者ID:boris-savic,項目名稱:python-furs-fiscal,代碼行數:6,代碼來源:base_api.py

示例8: test_success

# 需要導入模塊: from OpenSSL import crypto [as 別名]
# 或者: from OpenSSL.crypto import sign [as 別名]
def test_success(self):
        decrypted_key = _mtls_helper.decrypt_private_key(
            ENCRYPTED_EC_PRIVATE_KEY, PASSPHRASE_VALUE
        )
        private_key = crypto.load_privatekey(crypto.FILETYPE_PEM, decrypted_key)
        public_key = crypto.load_publickey(crypto.FILETYPE_PEM, EC_PUBLIC_KEY)
        x509 = crypto.X509()
        x509.set_pubkey(public_key)

        # Test the decrypted key works by signing and verification.
        signature = crypto.sign(private_key, b"data", "sha256")
        crypto.verify(x509, signature, b"data", "sha256") 
開發者ID:googleapis,項目名稱:google-auth-library-python,代碼行數:14,代碼來源:test__mtls_helper.py

示例9: __init__

# 需要導入模塊: from OpenSSL import crypto [as 別名]
# 或者: from OpenSSL.crypto import sign [as 別名]
def __init__(self, pkey):
        """Constructor.

        Args:
            pkey: OpenSSL.crypto.PKey (or equiv), The private key to sign with.
        """
        self._key = pkey 
開發者ID:Deltares,項目名稱:aqua-monitor,代碼行數:9,代碼來源:_openssl_crypt.py

示例10: sign

# 需要導入模塊: from OpenSSL import crypto [as 別名]
# 或者: from OpenSSL.crypto import sign [as 別名]
def sign(self, message):
        """Signs a message.

        Args:
            message: bytes, Message to be signed.

        Returns:
            string, The signature of the message for the given key.
        """
        message = _to_bytes(message, encoding='utf-8')
        return crypto.sign(self._key, message, 'sha256') 
開發者ID:Deltares,項目名稱:aqua-monitor,代碼行數:13,代碼來源:_openssl_crypt.py


注:本文中的OpenSSL.crypto.sign方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。