ERROR 9425: Image access denied: This account doesn't have variant with this name

What’s wrong with me?

https://imagedelivery.net/SzNV43bIOhJnWJ5Iz6Cvhg/932c3295-9ef0-43c0-45cf-082dd1d6ed01/public&sig=98A21AAC14D2EDBB3010E1D2D85D3FF657EA6409FF9092CAF3890E8E1CB4B1DE

URL params (sig in this case) are added at the end with ? and then & as a separator. I believe right now it’s literally trying to find a variant named public&sig=98A21AAC14D2EDBB3010E1D2D85D3FF657EA6409FF9092CAF3890E8E1CB4B1DE

If you fix this then I get the following error:

This makes a lot more sense, make sure you generate the signature as specified here

For example, key is 111

The content is https://imagedelivery.net/SzNV43bIOhJnWJ5Iz6Cvhg/932c3295-9ef0-43c0-45cf-082dd1d6ed01/public?exp=1632165833

The encrypted value is 1d160cf8c35752b652a3d5fc542634560e7a990091ea1073cd6fb42822f5a349. That’s right

But I c# got 4090da18a78252c31e4e43dbb89ec78e79a8d7db3199285ac1204c7043819eab

Is there a problem with the following code.

public static string Encrypt(string message, string secret)
{

        var encoding = new System.Text.UTF8Encoding();
        byte[] keyByte = encoding.GetBytes(secret);
        byte[] messageBytes = encoding.GetBytes(message);
        using (var hmacsha256 = new HMACSHA256(keyByte))
        {
            byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < hashmessage.Length; i++)
            {
                builder.Append(hashmessage[i].ToString("x2"));
            }
            return builder.ToString();
        }
    }

I don’t know why I have a problem with c# encryption?

        string sig=  Encrypt("https://imagedelivery.net/SzNV43bIOhJnWJ5Iz6Cvhg/932c3295-9ef0-43c0-45cf-082dd1d6ed01/public","111");

Looks like you’re generating the hash incorrectly. Per the example I sent you need to use the path + expiration time and then also provide expiration time in the final URL.

Here is an example URL:
https://imagedelivery.net/pG6EjIJh1pVsLb2GkO_Y0A/c07f2865-38a1-49ac-2f1a-529de982d601/banner?exp=1900000000000&sig=ee182be81601729bce4460cf0ddee3ec19993c6a878479183b3a8fc979f24d16

How did I compute this hash? Well, it comes down to this:
sha256Hmac('/pG6EjIJh1pVsLb2GkO_Y0A/c07f2865-38a1-49ac-2f1a-529de982d601/banner?exp=1900000000000')
You need the whole path (so, account ID, image ID, variant (if applicable) and the expiration time).
Then you will use your token as the secret key (you can get that here: https://dash.cloudflare.com?to=/:account/images/keys)

You can use a tool like Free HMAC-SHA256 Online Generator Tool | Devglan to test this and try to get a valid URL. Once you know your values are correct, you can put them into C#.

Let me know if you need anymore help!

2 Likes

This topic was automatically closed after 15 days. New replies are no longer allowed.