Skip to content

Instantly share code, notes, and snippets.

View pbteja1998's full-sized avatar

Bhanu Teja Pachipulusu pbteja1998

View GitHub Profile
def hash_data(data):
'''
param: data b64encoded data
return: SHA256 base64 encoded hash
'''
from base64 import b64decode
from Crypto.Hash import SHA256
hashed_data = SHA256.new()
hashed_data.update(b64decode(data))
return hashed_data
def generate_RSA(bits=2048):
'''
Generate an RSA keypair with an exponent of 65537 in PEM format
param: bits The key length in bits
Return private key and public key
'''
from Crypto.PublicKey import RSA
new_key = RSA.generate(bits, e=65537)
public_key = new_key.publickey().exportKey("PEM")
private_key = new_key.exportKey("PEM")
def verify_sign(public_key, signature, hashed_data):
'''
Verifies with a public key from whom the data came that it was indeed
signed by their private key
param: public_key
param: signature String signature to be verified
return: Boolean. True if the signature is valid; False otherwise.
'''
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
def sign_data(private_key, hashed_data):
'''
param: private_key
param: hashed_data SHA256 hash of data to be signed
return: base64 encoded signature
'''
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
from base64 import b64encode
key = private_key
@pbteja1998
pbteja1998 / readme.md
Created November 22, 2017 07:07 — forked from vinaypuppal/readme.md
GITHUB_OAUTH
  • On Frontend
    • User clicks Login With Github Button.
    • We redirect user to https://github.com/login/oauth/authorize with client_id, redirect_uri and scope as query params.
    • Example
      https://github.com/login/oauth/authorize?scope=user:email&client_id=<CLIENT_ID>&state=<state>
      
    • Once user allows access github redirect back us to supplied redirect_uri with code as query parameter.
    • Example
@pbteja1998
pbteja1998 / scopes.txt
Created September 22, 2017 17:28 — forked from iambibhas/scopes.txt
Sublime Text 2: Snippet scopes
Here is a list of scopes to use in Sublime Text 2 snippets -
ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
CoffeeScript: source.coffee