1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-24 08:12:38 +02:00
imgproxy/examples/signature-cloudfront-functions.js
Lev Novikov 78af338d65
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
2023-10-25 18:18:33 +02:00

20 lines
613 B
JavaScript

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)