The code is a reference from the WordPress AMP plugin
/**
* Function to generate AMP scrip hash.
*
* @param string $script the script as a string to generate the hash.
*
* @return string hash generated from the script.
*/
function amp_generate_script_hash( $script ) {
$sha384 = hash( 'sha384', $script, true );
if ( false === $sha384 ) {
return null;
}
$hash = str_replace(
[ '+', '/', '=' ],
[ '-', '_', '.' ],
base64_encode( $sha384 )
);
return 'sha384-' . $hash;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…