Next.js Discord

Discord Forum

ERR_OSSL_UNSUPPORTED

Answered
Black Caiman posted this in #help-forum
Open in Discord
Black CaimanOP
Hello, need some help regarding this error. I tried searching from google and found out private key corrupts something like that but I wanna make sure where this error comes from.
Answered by Black Caiman
Here's what I did

const convertPrivateKey = Buffer.from(process.env.CLOUDFRONT_PRIVATE_KEY, 'base64')

copy the value of the convertPrivateKey and add it to you env.local

const privateKey = Buffer.from(process.env.CLOUDFRONT_PRIVATE_KEY_BASE64, 'base64').toString(
    'ascii'
  );


this privateKey will be the one you'll have add to in you're privateKey params and you can delete the convertPrivateKey since we just need the base64 converted string
View full answer

61 Replies

Black CaimanOP
Here is code snippets for reference:

import { getSignedUrl } from '@aws-sdk/cloudfront-signer';
export default function handler(req, res) {
  const { imageName } = req.body;

  if (req.method !== 'POST') return res.status(405);

  if (!imageName && !imageUrl)
    return res.status(400).json({ message: 'Invalid payload. Required image url and name' });

  const params = {
    keyPairId: process.env.CLOUDFRONT_KEY_PAIR_ID,
    privateKey: privateKey,
    url: 'https://example.cloudfront.net/' + imageName,
    dateLessThan: new Date(Date.now() + 1000 * 60 * 60 * 24),
  };

  const signedUrl = getSignedUrl(params);

  res.status(200).json({ message: 'Success', signedUrl });
}
looking good. Where does privateKey comes from?
Black CaimanOP
I didn't setup the cloudfront but I send my boss a youtube for reference https://youtu.be/EIYrhbBk7do?feature=shared&t=240
the video uses openssl
yea, some time ago this video also helped me to set things up xD
privateKey: privateKey,

I mean this one. Where do you define this one?
Black CaimanOP
const privateKey = process.env.CLOUDFRONT_PRIVATE_KEY;
I added it on the env file
ah ok... I also got this error when I done this via cloudfront. For me the solution was to let the value of the private key like it is. In my case some line breaks are removed and because of that it couldnt be verified. Maybe that's the same in your case while getting this of your enviorment variables
Black CaimanOP
I'm sorry I don't quite understand 😅
your private key looks like this
and in my case all the orange points were on one line. So my line breaks are gone and the key don't work
Black CaimanOP
ohh so I need to replace that line breaks right?
the key needs to be like you generated it. So: with line breaks
Black CaimanOP
I tried adding double quotes and no double qoutes yet still got the same error
am also verifyng if the key id is correct
just to try if this is the problem: please try to put it hardcode inside your code and let's see if that works ^^
Black CaimanOP
still not work hardcoded T___T
hahaha nice xD
than don't have any idea 💀
Black CaimanOP
hahahahaha
i want to be a butterfly right now 😭
a butterfly?
Black CaimanOP
yeah so I don't have to code all my life and just fly fly flyy hahahaha
don't you like coding? like with all the difficulty it brings?
Black CaimanOP
I like it sometimes HAHAHAHAH
haha, what do you think about bunnycdn?
Black CaimanOP
what's that? is that something to do with bun?
update the cloudfront_key_pair_id but still got the same error
T___T
i just wanna cry
@Black Caiman what's that? is that something to do with bun?
it's like cloudfront but just an own provider for that. I am currently using that ^^
Black CaimanOP
it works now
T___T
but it's hardcoded hahahaha
then it was due to the line breaks?
Black CaimanOP
so the \n should be after BEGIN and before the END only
yeahh
ohhhhh nice. So you get the signed url now?
Black CaimanOP
yeahhh!!
Black CaimanOP
but I still want to be butterfly HAHAHAHA
anywayy
thankyouuusomuchh again!!!
haha nice thx for marking the right one :lolsob:
Black CaimanOP
no probleem and that's cool emoji hahahahah
Whip-poor-will
@Black Caiman how did you fix this? I dont get what you did differenty ?
like remove any other \n outside of the one after --BEGIN PRIVATE KEY--- \n and then before ---END PRIVATE KEY---
Black CaimanOP
Here's an update, it didn't work on deployment but locally works fine.
Whip-poor-will
ahh yeah mine works locally but on vercel deployment I am getting the same error - ERR_OSSL_UNSUPORTED
Black CaimanOP
Here's what I did

const convertPrivateKey = Buffer.from(process.env.CLOUDFRONT_PRIVATE_KEY, 'base64')

copy the value of the convertPrivateKey and add it to you env.local

const privateKey = Buffer.from(process.env.CLOUDFRONT_PRIVATE_KEY_BASE64, 'base64').toString(
    'ascii'
  );


this privateKey will be the one you'll have add to in you're privateKey params and you can delete the convertPrivateKey since we just need the base64 converted string
Answer
Black CaimanOP
hope this helps @Whip-poor-will
Whip-poor-will
i'll give this a try
so this helped you with prod environement ?
Black CaimanOP
I found this actually in stackoverflow but I forgot the link hahaha
yepp
Whip-poor-will
const convertPrivateKey = Buffer.from(process.env.CLOUDFRONT_PRIVATE_KEY, 'base64')


This may sound dumb but how do you copy this value?
Black CaimanOP
just console.log it then copy
Whip-poor-will
this worked !