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

PHP openssl SHA256 signature verification

By: zedwood on Mar 16th, 2012  |  syntax: PHP  |  size: 8.55 KB  |  views: 812  |  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. <?php
  2. $alg=OPENSSL_ALGO_SHA1;
  3. $data=base64_decode("MIIBUAIBADAjMQswCQYDVQQGEwJVUzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDbKbqEsAxX/+IxGMTH8ff5G5UdgutCd0nlr9MTaPwiBBtLZJSAcrljQ9Di8prAKLMeRRnqAy/iw8dsYptaQvozsJIqgXHn59Z22nqCxrt9veIsPLpkanBNvtTulrMNNIXPVZZ3Gy168yOVlB8nfb5rFRmxWiw4ADkiUhGaJ9dfWETp41fCq7OXqKTp9SSFxBn+4gBwLjdSFYJfVX3K3xldk9RIRQpaRcXl+l0Hvu4WUW8y6WPm1Isq6lTd5cBgqC2Jnagra8azwHt0n2HibwW+o3t94Bnxkkw2/xx6K6O0cHPaIMg2yexY/CiKUwkC06Dy9KFVzsogL7phX0UtxpcrAgMBAAGgAA==");
  4. $sig=base64_decode("ZDlCKIvpaPOJ9mKG7hXn39hCMPdTPOUMKfRmt4BRLYT9EN5RCkfnhK4CLy1sN8vBp1S2BKhHd0neO6N5nc5cCH1u/eeNVE2zd6Xxqut04Ax4WQ91qVhZYd+3LwYLTnAkeQ1uFyd+sH0HHLJb9ewaWTsPJgByLqwk+2xih6ASqThnS9dfWkpuPivmDjVunPk2v0XWsKkpqv7vpjvCKws2LSXNe8VGPBv43HJQ+qkHmaXPxzvbGbkKEbJK3u2RRRFUeulzF5PM8ZPeitgOpEwcRSkV9W3oPyHd+67A7j4IjMm9NDF9he1wN5mf/lRZLmiEoHYKncpY1rsfQ1pVwHc7fw==");
  5. $key=implode("\n", array('-----BEGIN PUBLIC KEY-----', 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2ym6hLAMV//iMRjEx/H3','+RuVHYLrQndJ5a/TE2j8IgQbS2SUgHK5Y0PQ4vKawCizHkUZ6gMv4sPHbGKbWkL6','M7CSKoFx5+fWdtp6gsa7fb3iLDy6ZGpwTb7U7pazDTSFz1WWdxstevMjlZQfJ32+','axUZsVosOAA5IlIRmifXX1hE6eNXwquzl6ik6fUkhcQZ/uIAcC43UhWCX1V9yt8Z','XZPUSEUKWkXF5fpdB77uFlFvMulj5tSLKupU3eXAYKgtiZ2oK2vGs8B7dJ9h4m8F','vqN7feAZ8ZJMNv8ceiujtHBz2iDINsnsWPwoilMJAtOg8vShVc7KIC+6YV9FLcaX','KwIDAQAB', '-----END PUBLIC KEY-----'));
  6. echo openssl_verify($data,$sig,$key,$alg) ? 'verified'."\n" : 'invalid'."\n";
  7.  
  8. $alg=OPENSSL_ALGO_RMD160;
  9. $data=base64_decode("MIIBUAIBADAjMQswCQYDVQQGEwJVUzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDWzBV2ULYZtEljrPbcLWV6rIcwpyrrxY6O67zhzXlv79RVM/HBNPxcR0k/kPFuSDePc7QPsiNRTMdK5IbdOKC2+PE4iMhjTLtzp6D3+MgY8BBESJOLwTKbQ17L5YsnjKxYgRTRgxIXR/lcDEtmGBYMQefGiH6SDi1x6eP1nfK3W8TtJcBPomQpikNqb64itQ+ieBZXmWIusXc0T2G9P0V9eaDH6mYvn++fC9HaX564IwREBo3r5xdZ9XMVdnon4HqKFHwQ22LugdIaAXmg5RbeGYnJUkezAAh7X3UESWVG7SG/YJGb3eMRN7+v/lcM6ypsdsJIfVWbwJoImYEXsgxbAgMBAAGgAA==");
  10. $sig=base64_decode("MG9aOi4rH4pKcZI9Dj1mPPpoXOqiqORwgH2BVGkd9DAGtVre3lH9YxhZx2NpUy4RwryQlQR5IVdJzUj/zb8spcTawf3ZcWoqZP5pT08f8Scuvzm9cbBhOhc2503Z1Dc24DlPVd3YYFBt31CbWZdzOZPT3S3EzO9/0mSMRBeXnDRmlr7rotpGSIbzGLqMLOArw/0FA3/tTfex21uF+cJAORXNTG9Yo/4os5YpU3HoV2zWfzw6qBGF3E4vFANenK02NLPTxHjYw8EI96QwwlXgdGXpZFWhmbJ4+1b131ZxzGzkruzPSDWV2la9498yj92nnTDzpBIwXRBxZcXNw2DDCg==");
  11. $key=implode("\n", array('-----BEGIN PUBLIC KEY-----', 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1swVdlC2GbRJY6z23C1l','eqyHMKcq68WOjuu84c15b+/UVTPxwTT8XEdJP5Dxbkg3j3O0D7IjUUzHSuSG3Tig','tvjxOIjIY0y7c6eg9/jIGPAQREiTi8Eym0Ney+WLJ4ysWIEU0YMSF0f5XAxLZhgW','DEHnxoh+kg4tcenj9Z3yt1vE7SXAT6JkKYpDam+uIrUPongWV5liLrF3NE9hvT9F','fXmgx+pmL5/vnwvR2l+euCMERAaN6+cXWfVzFXZ6J+B6ihR8ENti7oHSGgF5oOUW','3hmJyVJHswAIe191BEllRu0hv2CRm93jETe/r/5XDOsqbHbCSH1Vm8CaCJmBF7IM','WwIDAQAB', '-----END PUBLIC KEY-----'));
  12. echo openssl_verify($data,$sig,$key,$alg) ? 'verified'."\n" : 'invalid'."\n";
  13.  
  14. $alg=OPENSSL_ALGO_SHA224;
  15. $data=base64_decode("MIIBUAIBADAjMQswCQYDVQQGEwJVUzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCrX60YBiN9mSvf5V/25+cry+3uDR6eRbKFp4tZMGXRTVqNt04nOARVxxOLjRNOVwLrThweryGX5sq96FZENcchUD1hotbDmuIOZmCkRvD8ZuOsglG8VVCXw/i0q8CoGt+9OSArpoZVprbtBZdLA2orgBpXAaE5ByVGzOI5pLJxQxVG7hvCIGCP9pp9oLw6A5B8ta8J5RbaJmpmAIDd0oO0n+AKNhwlx3jtm9q1Jgskax8stGj/DhmRE2+xEeyaZ8U4YXR3P3c82N73ZWXk43VgbxWgw07TAD6jvYBrPE9OnkZojqOSbIxvHMZb1Z0NxaBmmiFfgZxUMdhdpUSxLTBxAgMBAAGgAA==");
  16. $sig=base64_decode("nDZGEQNdz/t9w7pgCMdL6QYTD3Ah/jW87CMw5OJvOUz/cdCgXpJI2USzdMotpzYyH37Xu45J53wLDGrp3ec6CdhqisLzPKNAwkjFyHB8ow3Hc/sNVPAEw8uHFDAvumevWF1Yu3SF3Lzc/SGgSohhU6vVuoPUULPuzfUoeTiMm7IWi4h2JLMIx2p3EVR15B+WxADJrMxMJ2HIdNWXliZCMT3yXL4nsvdmjl1pzruxGmUHuXpMeiWSyHP4+Nw2/HnIBC9ckSC2h8d4KNl2U4Zw1792dqAQKO2JukP9p0o182heGgD8+ovNkmdmL9ZTrQsEw226M6qcZ3aWpYvWYkdqtw==");
  17. $key=implode("\n", array('-----BEGIN PUBLIC KEY-----', 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq1+tGAYjfZkr3+Vf9ufn','K8vt7g0enkWyhaeLWTBl0U1ajbdOJzgEVccTi40TTlcC604cHq8hl+bKvehWRDXH','IVA9YaLWw5riDmZgpEbw/GbjrIJRvFVQl8P4tKvAqBrfvTkgK6aGVaa27QWXSwNq','K4AaVwGhOQclRsziOaSycUMVRu4bwiBgj/aafaC8OgOQfLWvCeUW2iZqZgCA3dKD','tJ/gCjYcJcd47ZvatSYLJGsfLLRo/w4ZkRNvsRHsmmfFOGF0dz93PNje92Vl5ON1','YG8VoMNO0wA+o72AazxPTp5GaI6jkmyMbxzGW9WdDcWgZpohX4GcVDHYXaVEsS0w','cQIDAQAB', '-----END PUBLIC KEY-----'));
  18. echo openssl_verify($data,$sig,$key,$alg) ? 'verified'."\n" : 'invalid'."\n";
  19.  
  20. $alg=OPENSSL_ALGO_SHA256;
  21. $data=base64_decode("MIIBUAIBADAjMQswCQYDVQQGEwJVUzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDLvHh380Z3qoN1yqIqeI5I7ISvvTFlbzfc+nG8xzgPK/p8JNP3X7Wv7EOlAjizdgKN3aofV9j3i5FwiUXeJ8kDTu5zxMDtJwuslNC3/iDi/jljtNRyJZTSzPW/t2UZlnR7KWJnuTK4HA7rLsQZ/EV6BMQtodUTvKV99rMgKnPRrB+vOILKH/YY7AcZ7lbsq1sQLS+JfbovKYfGLuc9xBE6PwAlqUb5ayYEI7Ea8aMtKlwi5ND5WgFKJFejcmkZQvAps79ZTkk+oQ3DmUxK233pDLrtkhUunnijc2iLOnr+jC3D+PaYOfR4Z0qviY0lbCo9byVpiuLk79kG12g4w/+vAgMBAAGgAA==");
  22. $sig=base64_decode("ZwVuKM4DkRrPpfznzW+X081MNE4iaU2asf8tL34D5anV4Bbyf5H+EpbwnO9RRrlZ5T+Gn+vmk4+lv1NquH/q8ur/l3e3o3TXkOZpZi3FR6MFKRVTirIB8BIOeQuhN9KayDTzlVZIzQtC2ygDP5UG1EPSt9ruCS7Lm7poyqoHQhxTv04PBppJOY9c+nB+sGs3sMBh25hJvuFRqv190fSupahker4Eh9aj/NdxVG7lWarvGOzipGMPQHTEXxZuLD/CrXW2O9VcHjxWNfsT84Xo42f8e9x8qIFNUZXJutGfBk9Yq2UyYHBp27uvXRyYtWT4RRkczkVa/00Nq43Pee3JsA==");
  23. $key=implode("\n", array('-----BEGIN PUBLIC KEY-----', 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy7x4d/NGd6qDdcqiKniO','SOyEr70xZW833PpxvMc4Dyv6fCTT91+1r+xDpQI4s3YCjd2qH1fY94uRcIlF3ifJ','A07uc8TA7ScLrJTQt/4g4v45Y7TUciWU0sz1v7dlGZZ0eyliZ7kyuBwO6y7EGfxF','egTELaHVE7ylffazICpz0awfrziCyh/2GOwHGe5W7KtbEC0viX26LymHxi7nPcQR','Oj8AJalG+WsmBCOxGvGjLSpcIuTQ+VoBSiRXo3JpGULwKbO/WU5JPqENw5lMStt9','6Qy67ZIVLp54o3Noizp6/owtw/j2mDn0eGdKr4mNJWwqPW8laYri5O/ZBtdoOMP/','rwIDAQAB', '-----END PUBLIC KEY-----'));
  24. echo openssl_verify($data,$sig,$key,$alg) ? 'verified'."\n" : 'invalid'."\n";
  25.  
  26. $alg=OPENSSL_ALGO_SHA384;
  27. $data=base64_decode("MIIBUAIBADAjMQswCQYDVQQGEwJVUzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDOe3AThZ4Tt4JYz6p6yl0mP8WLeqE5s1fJmnibPuE+N7UTAweTQS6tBtvY0xvHAEA5B4fbIrUAoAIcGqRwYnVDN8396keZ8uavTTb+R14vnAOc/eDtQkhGVQOU32V12gk5sPVGUL0fUH/xI5O7iADHIjeAJTty593pFuXJKiqUq5EWDYdBmalSM8Dr+6r29LA9t8hEvjfHuc6JRRKVKQYQ95ejmOg9hiuk/XU3Z+tZ1YmZnQ7PGNhCPkexpGNrQMSNVHekufw8xMxujnVHSNrhpAG64AOErcF5ICgFLD0hqtejTH+t9TqHXmiqhzqBZhP5rlr/hOHuw/lRy+wcHvLfAgMBAAGgAA==");
  28. $sig=base64_decode("WO4a0zzOMUFzPTI/h0/DS7ldJFb1OsFTRVnJ+ZHDUaNSZIWthdWjEbH9qalvPaRP/OR3M4luOBEYEM0CursndOBremXs21RDmXsM45VrpEk4zT3TCZz1FnWFnus0k7GdI51kXzf08HqxkVuj+Bmo9tJzJNI8wlpt+tiKP/SxtplyPizRVm80xNwMRxUn5gEHVtJsaIj3P+DAgaFK0zsWqUgU8Xt/9X8LBfpEInzN1GuEXSlR3i8a7zr1vQrGsZRT4wh3RYzsRXHQb/AfOwTML97kfdr5EJZyTj+hcpBp3W2srVKV5GZksPNSgY1GIqysFlG6xpkbw2s+b6/sJCkn6A==");
  29. $key=implode("\n", array('-----BEGIN PUBLIC KEY-----', 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzntwE4WeE7eCWM+qespd','Jj/Fi3qhObNXyZp4mz7hPje1EwMHk0EurQbb2NMbxwBAOQeH2yK1AKACHBqkcGJ1','QzfN/epHmfLmr002/kdeL5wDnP3g7UJIRlUDlN9lddoJObD1RlC9H1B/8SOTu4gA','xyI3gCU7cufd6RblySoqlKuRFg2HQZmpUjPA6/uq9vSwPbfIRL43x7nOiUUSlSkG','EPeXo5joPYYrpP11N2frWdWJmZ0OzxjYQj5HsaRja0DEjVR3pLn8PMTMbo51R0ja','4aQBuuADhK3BeSAoBSw9IarXo0x/rfU6h15oqoc6gWYT+a5a/4Th7sP5UcvsHB7y','3wIDAQAB', '-----END PUBLIC KEY-----'));
  30. echo openssl_verify($data,$sig,$key,$alg) ? 'verified'."\n" : 'invalid'."\n";
  31.  
  32. $alg=OPENSSL_ALGO_SHA512;
  33. $data=base64_decode("MIIBUAIBADAjMQswCQYDVQQGEwJVUzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDImFVtjhxoxNKG21BDRIm5USaBDbG91aQ3/usoUWHlZoyHJv0Mex99dKBwVihOgoKikkv7yj5zbIXgn/I0z7KLt/sFL95pORI85xrxdvOhiEttEEmUh1RKxZgTeQ/uw6uuVm2kIpm8Z6x+4gnlTsSJjmov9lw5UZmL03fZ77WJjsKMExdx9UosFFBfg0bs/E1wU+Sx6ZmfQHQALdGZeA3JkBk+YrWebqIXK8wfjau2Vo+WkAaom/tPJ7ErdxbTVjUynwdzAQLa8qPOHrftAjPxCDXG/jQ0wDveuYPX7mDmw7SIX3YTru6GCTSJtDxfmI5N6JFQ8zgFXcjxs9s2uPrHAgMBAAGgAA==");
  34. $sig=base64_decode("Dy2U+sh3JAfMpSTJGEcH5HglC7aRKIEByY8jf62PmHMxZHHUDMFGENb0xLJnV+VNe3OlhEBrQX208ZfnsYGmmYr7SEyqof6rva+/bZiVIq+h+vfvrmnQdYehtSd3HIVT1q1CV+RSqzDe5CPuFhCryCzs92zefCm4FIuNb5GaacYg/BJqoTV7MGFI+9tGOX8TJTcVZBcnrUSQmumrjPK3SATpPS3ehHMKCZJy/l1bcZqEvcUHTUyaRRwGcVY23Jqk7ms4vNzDC6xX/K5xjD+aEpIdHNPIOB6NzXauO9aSsJ99rr4wyiPHNIsM48TALeih6x7d81EscBYPdsFNSYijkw==");
  35. $key=implode("\n", array('-----BEGIN PUBLIC KEY-----', 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyJhVbY4caMTShttQQ0SJ','uVEmgQ2xvdWkN/7rKFFh5WaMhyb9DHsffXSgcFYoToKCopJL+8o+c2yF4J/yNM+y','i7f7BS/eaTkSPOca8XbzoYhLbRBJlIdUSsWYE3kP7sOrrlZtpCKZvGesfuIJ5U7E','iY5qL/ZcOVGZi9N32e+1iY7CjBMXcfVKLBRQX4NG7PxNcFPksemZn0B0AC3RmXgN','yZAZPmK1nm6iFyvMH42rtlaPlpAGqJv7TyexK3cW01Y1Mp8HcwEC2vKjzh637QIz','8Qg1xv40NMA73rmD1+5g5sO0iF92E67uhgk0ibQ8X5iOTeiRUPM4BV3I8bPbNrj6','xwIDAQAB', '-----END PUBLIC KEY-----'));
  36. echo openssl_verify($data,$sig,$key,$alg) ? 'verified'."\n" : 'invalid'."\n";