【发布时间】:2021-04-27 05:09:18
【问题描述】:
在Calculating the script hash,我们可以看到如何计算 AMP 情况下的 JavaScript 哈希:
const crypto = require('crypto');
const hash = crypto.createHash('sha384');
function generateCSPHash(script) {
const data = hash.update(script, 'utf-8');
return (
'sha384-' +
data
.digest('base64')
.replace(/=/g, '')
.replace(/\+/g, '-')
.replace(/\//g, '_')
);
}
如何在 PHP 中做同样的事情?以下似乎不起作用:
<?php
$hash = base64_encode( hash( 'SHA384', 'Give me my hash!', true ) );
【问题讨论】:
标签: javascript php hash amp-html