Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. $policy_utf = utf8_encode($policy);//ensure utf-8
  2. $policy_base64 = base64_encode($policy_utf);//encoded by base64
  3.  
  4. $signature = googleSignString('docker-71ea7c875c5e.p12', $policy_base64);
  5.  
  6. /*
  7. * @params p12FilePath Service account p12 file path
  8. * @params string Plain text for encoding
  9. */
  10. function googleSignString($p12FilePath, $string){
  11. $certs = [];
  12. if (!openssl_pkcs12_read(file_get_contents($p12FilePath), $certs, 'notasecret'))
  13. {
  14. echo "Unable to parse the p12 file. OpenSSL error: " . openssl_error_string(); exit();
  15. }
  16. $RSAPrivateKey = openssl_pkey_get_private($certs["pkey"]);
  17. $signed = '';
  18. if(!openssl_sign( $string, $signed, $RSAPrivateKey, 'sha256' ))
  19. {
  20. error_log( 'openssl_sign failed!' );
  21. $signed = 'failed';
  22. }
  23. else
  24. {
  25. $signed = base64_encode($signed);
  26. }
  27. return $signed;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement