1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-02-02 11:34:20 +02:00

Fixed browser usage

Using `const createHmac = require('create-hmac')` will ensure that this script will work both on Node.js and Browser (otherwise it will crash on browser).
I've also updated `new Buffer` on line 7, which is deprecated in flavor of `Buffer.from`
This commit is contained in:
Sleva λ 2019-09-04 23:31:20 +02:00 committed by GitHub
parent e6deed2b0a
commit fd206600a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,16 +1,16 @@
const crypto = require('crypto')
const createHmac = require('create-hmac')
const KEY = '943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881'
const SALT = '520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5'
const urlSafeBase64 = (string) => {
return new Buffer(string).toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_')
return Buffer.from(string).toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_')
}
const hexDecode = (hex) => Buffer.from(hex, 'hex')
const sign = (salt, target, secret) => {
const hmac = crypto.createHmac('sha256', hexDecode(secret))
const hmac = createHmac('sha256', hexDecode(secret))
hmac.update(hexDecode(salt))
hmac.update(target)
return urlSafeBase64(hmac.digest())