Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error generating CloudFront signed URL: Error: error:1E08010C:DECODER routines::unsupported at Sign.sign (node:internal/crypto/sig:128:29) #4526

Open
2 tasks done
GS2227 opened this issue Jan 6, 2025 · 0 comments

Comments

@GS2227
Copy link

GS2227 commented Jan 6, 2025

Node.js Version

22.12.0

NPM Version

10.9.0

Operating System

root:xnu-10063.101.17~1/RELEASE_ARM64_T8112 arm64

Subsystem

buffer

Description

async getSignedURL(filePath: string) {
try {
const privateKey = fs.readFileSync('private-key.pem', { encoding: 'utf8' });//.replace(/\n/g, '\n');
console.log("privateKey", privateKey);

  const url = `https://${cdn_domain}.d1a3sb2t664pk3.cloudfront.net/${filePath}`;
  const keyPairId = this.cloudFrontKeyPairId;

  const dateLessThan = Math.floor((Date.now() + 60 * 60 * 1000) / 1000);

  const policy = {
    Statement: [
      {
        Resource: url,
        Condition: {
          DateLessThan: {
            "AWS:EpochTime": new Date(dateLessThan).getTime() / 1000,
          },
        },
      },
    ],
  };
  const signedUrl = await getSignedUrl({
    url: url,
    privateKey: privateKey,
    keyPairId: keyPairId,
    policy: JSON.stringify(policy),
  });

  console.log("Signed URL:", signedUrl);
  return signedUrl;
} catch (error) {
  console.error("Error generating CloudFront signed URL:", error);
  throw error;
}

}

Minimal Reproduction

No response

Output

privateKey -----BEGIN PRIVATE KEY-----djfnhjidnfefjnijfnhienhgvijufnvjlk-----END PRIVATE KEY-----
Error generating CloudFront signed URL: Error: error:1E08010C:DECODER routines::unsupported
at Sign.sign (node:internal/crypto/sig:128:29)

[error] error:1E08010C:DECODER routines::unsupported. METADATA: {"metadata":{"stack":"Error: error:1E08010C:DECODER routines::unsupported\n at Sign.sign (node:internal/crypto/sig:128:29)\n at _CloudfrontSignBuilder.signData

Before You Submit

  • I have looked for issues that already exist before submitting this
  • My issue follows the guidelines in the README file, and follows the 'How to ask a good question' guide at https://stackoverflow.com/help/how-to-ask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant