You've already forked imgproxy
mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-12-05 23:28:10 +02:00
Create signature-cloudfront-functions.js
Modified signature.js for use in AWS CloudFront Functions. About JS runtime and restrictions - https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-javascript-runtime-features.html
This commit is contained in:
19
examples/signature-cloudfront-functions.js
Normal file
19
examples/signature-cloudfront-functions.js
Normal file
@@ -0,0 +1,19 @@
|
||||
var crypto = require('crypto');
|
||||
|
||||
var KEY = '943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881'
|
||||
var SALT = '520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5'
|
||||
|
||||
var hexDecode = (hex) => String.bytesFrom(hex, 'hex')
|
||||
|
||||
var sign = (salt, target, secret) => {
|
||||
var hmac = crypto.createHmac('sha256', hexDecode(secret))
|
||||
hmac.update(hexDecode(salt))
|
||||
hmac.update(target)
|
||||
|
||||
return hmac.digest('base64url')
|
||||
}
|
||||
|
||||
var path = "/rs:fit:300:300/plain/http://img.example.com/pretty/image.jpg"
|
||||
var signature = sign(SALT,path,KEY)
|
||||
var result = `/${signature}${path}`
|
||||
console.log(result)
|
||||
Reference in New Issue
Block a user