Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $policy_utf = utf8_encode($policy);//ensure utf-8
- $policy_base64 = base64_encode($policy_utf);//encoded by base64
- $signature = googleSignString('docker-71ea7c875c5e.p12', $policy_base64);
- /*
- * @params p12FilePath Service account p12 file path
- * @params string Plain text for encoding
- */
- function googleSignString($p12FilePath, $string){
- $certs = [];
- if (!openssl_pkcs12_read(file_get_contents($p12FilePath), $certs, 'notasecret'))
- {
- echo "Unable to parse the p12 file. OpenSSL error: " . openssl_error_string(); exit();
- }
- $RSAPrivateKey = openssl_pkey_get_private($certs["pkey"]);
- $signed = '';
- if(!openssl_sign( $string, $signed, $RSAPrivateKey, 'sha256' ))
- {
- error_log( 'openssl_sign failed!' );
- $signed = 'failed';
- }
- else
- {
- $signed = base64_encode($signed);
- }
- return $signed;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement