mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-02-12 11:46:10 +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:
parent
e6deed2b0a
commit
fd206600a5
@ -1,16 +1,16 @@
|
|||||||
const crypto = require('crypto')
|
const createHmac = require('create-hmac')
|
||||||
|
|
||||||
const KEY = '943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881'
|
const KEY = '943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881'
|
||||||
const SALT = '520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5'
|
const SALT = '520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5'
|
||||||
|
|
||||||
const urlSafeBase64 = (string) => {
|
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 hexDecode = (hex) => Buffer.from(hex, 'hex')
|
||||||
|
|
||||||
const sign = (salt, target, secret) => {
|
const sign = (salt, target, secret) => {
|
||||||
const hmac = crypto.createHmac('sha256', hexDecode(secret))
|
const hmac = createHmac('sha256', hexDecode(secret))
|
||||||
hmac.update(hexDecode(salt))
|
hmac.update(hexDecode(salt))
|
||||||
hmac.update(target)
|
hmac.update(target)
|
||||||
return urlSafeBase64(hmac.digest())
|
return urlSafeBase64(hmac.digest())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user