Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Andrew B

By: a guest on Feb 15th, 2009  |  syntax: Python  |  size: 0.93 KB  |  views: 480  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def openssl_verify(data, sig, key, md='sha1'):
  2.     from M2Crypto import X509
  3.     x509 = X509.load_cert_string(key)
  4.     pubkey = x509.get_pubkey()
  5.     pubkey.reset_context(md=md)
  6.     pubkey.verify_init()
  7.     pubkey.verify_update(data)
  8.     return pubkey.verify_final(sig)
  9.  
  10. data = "1900847_4aaa6c7038653ad2e4dbeba175a679ba_1234576800"
  11. signature = "FkUmueUWrGShv3i+QYPJLFQA5XQeIIXJVFaOzr6lMgHUGCF4dd179atPUKG0FM+JVDF/ole+ZflQo44RU7sSa+NMaFh490ZLbCoz2hNx0c0FTjxKCXWvW9mSuRYOHutfUkIUX1/znwOzm2hqTo20qztO+X751ZaOtcQe6idaz94="
  12. public_key = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW\nnUEWzoBrPRF1NM8LqpOMD45FAPtZ1NmPtHGo0BAS1UsyJEGXx0NPJ8Gw1z+huLrl\nXnAVX5B4ec6cJfKKmpL/l94WhP2v8F3OGWrnaEX1mLMoxe124Pcfamt0SPCGkeal\nVvXw13PLINE/YptjkQIDAQAB\n-----END PUBLIC KEY-----\n"
  13. decoded_signature = signature.decode('base64')
  14. # prints "-1":
  15. print openssl_verify(data, decoded_signature, public_key);