def sign_json(body): private_key = load_key() rsa_key2 = private_key.getJwk() json = chilkat.CkJsonObject() json.Load(rsa_key2) json.put_EmitCompact(False) print("RSA Private Key in JWK format:") print(json.emit()) # Note: This example loads the RSA key from JWK format. Any format can be loaded # into the private key object. (See the online reference documentation..) rsaKey2 = chilkat.CkPrivateKey() success = rsaKey2.LoadJwk(json.emit()) if not success: print(rsaKey2.lastErrorText()) sys.exit() # Create the JWS Protected Header jwsProtHdr = chilkat.CkJsonObject() jwsProtHdr.AppendString("alg", "RS256") jws = chilkat.CkJws() # Set the protected header: signatureIndex = 0 jws.SetProtectedHeader(signatureIndex, jwsProtHdr) # Set the RSA key: jws.SetPrivateKey(signatureIndex, rsaKey2) # Set the payload. bincludebom = False payload_to_sign = body.decode("utf-8") print(payload_to_sign) jws.SetPayload(payload_to_sign, "utf-8", bincludebom) jws.put_PreferCompact(False) jws.put_PreferFlattened(True) # Create the JWS # By default, the compact serialization is used. jwsCompact = jws.createJws() print(jwsCompact) if (jws.get_LastMethodSuccess() != True): print(jws.lastErrorText()) sys.exit() json = chilkat.CkJsonObject() json.Load(jwsCompact) json.put_EmitCompact(False) print(json.emit()) return json.emit()
def main(args): # Load public key file into memory. sbPem = chilkat.CkStringBuilder() success = sbPem.LoadFile(args.public_key_file, "utf-8") if (success != True): print("Failed to load public key.") sys.exit() # Load the key file into a public key object. pubKey = chilkat.CkPublicKey() success = pubKey.LoadFromString(sbPem.getAsString()) if (success != True): print(pubKey.lastErrorText()) sys.exit() # Get the public key in JWK format: jwk = pubKey.getJwk() # Convert it to json format. json = chilkat.CkJsonObject() json.Load(jwk) # This line is used to set output format. cpt = True if (not args.compact) or (args.compact and args.compact == "no"): cpt = False json.put_EmitCompact(cpt) # Additional information can be added like this. change to fit needs. if args.alg: json.AppendString("alg", args.alg) if args.kid: json.AppendString("kid", args.kid) # Print. print("Generated " + args.alg + " public jwk:") print(json.emit())
def get_rsa_public_key_from_jwks(kty, e, n): json = chilkat.CkJsonObject() json.UpdateString("kty", kty) json.UpdateString("n", n) json.UpdateString("e", e) json.put_EmitCompact(False) jwkStr = json.emit() pubKey = chilkat.CkPublicKey() success = pubKey.LoadFromString(jwkStr) bPreferPkcs1 = False return pubKey.getPem(bPreferPkcs1)
http.ClearUrlVars() http.SetUrlVar("userPrincipalName", "*****@*****.**") #we've gathered the email id's into the function below message_ids = get_mail_idz() # Send the request to download the attachments for each of the emails for messageid in message_ids: http.SetUrlVar("message_id", messageid) success = http.QuickGetSb( "https://graph.microsoft.com/v1.0/users/{$userPrincipalName}/messages/{$message_id}/attachments", sbResponse) if ((success != True) and (http.get_LastStatus() == 0)): print(http.lastErrorText()) sys.exit() # The attachment data is contained within the JSON response. json = chilkat.CkJsonObject() json.LoadSb(sbResponse) json.put_EmitCompact(False) print("Status code = " + str(http.get_LastStatus())) if (http.get_LastStatus() != 200): print(json.emit()) print("Failed.") sbSavePath = chilkat.CkStringBuilder() attachData = chilkat.CkBinData() lastMod = chilkat.CkDateTime() fac = chilkat.CkFileAccess() i = 0 numMessages = json.SizeOfArray("value") while i < numMessages: json.put_I(i)
# Connect to the www.dropbox.com endpoint. bTls = True port = 443 bAutoReconnect = True success = rest.Connect("api.dropboxapi.com", port, bTls, bAutoReconnect) if (success != True): print(rest.lastErrorText()) sys.exit() rest.AddHeader("Content-Type", "application/json") rest.AddHeader( "Authorization", "Bearer f1X7SSCjr2AAAAAAAAABAgJAj5mnr62y5enONdcgwOCeIqoCr5BjRZidSyKdyXNg" ) json = chilkat.CkJsonObject() # The root folder should be an empty string, not "/" json.AppendString("path", "") json.AppendBool("recursive", False) json.AppendBool("include_media_info", False) json.AppendBool("include_deleted", False) json.AppendBool("include_has_explicit_shared_members", False) responseStr = rest.fullRequestString("POST", "/2/files/list_folder", json.emit()) if (rest.get_LastMethodSuccess() != True): print(rest.lastErrorText()) sys.exit() # Success is indicated by a 200 response status code. if (rest.get_ResponseStatusCode() != 200):