OAuth Signature

View as MarkdownOpen in Claude

Creating the OAuth Signature is a multi-stage process.

  1. First uses will need to create a sha256 hash of the encoded base string
  2. Next, you will need to create a PKCS1 v1.5 (Rfc2313) bytestring signature using your Private Encryption Key as an RSA key to sign our sha256 hash value created in our prior step.
  3. Once your bytestring has been generated, we will need to Base 64 encode our bytes, and then decode them using UTF-8 to receive a string value.
  4. Finally, we will need to URI escape our string, again using Rfc3986, to receive our final oauth_signature value.
1# Generate SHA256 hash of base string bytestring.
2sha256_hash = SHA256.new(data=encoded_base_string)
3
4# Generate bytestring PKCS1v1.5 signature of base string hash.
5# RSA signing key is private signature key.
6bytes_pkcs115_signature = PKCS1_v1_5_Signature.new(
7 rsa_key=signature_key
8 ).sign(msg_hash=sha256_hash)
9
10# Generate str from base64-encoded bytestring signature.
11b64_str_pkcs115_signature = base64.b64encode(bytes_pkcs115_signature).decode("utf-8")
12
13# URL-encode the base64 signature str and add to oauth params dict.
14oauth_params['oauth_signature'] = quote_plus(b64_str_pkcs115_signature)