Jump to content

Spot the wrong:

Recommended Posts

This thing does an xor encrypt on the selection from a series of sha512 hashes based on a user-input password. Works fine in codelab, screws up when compiled. I don't feel like putting it in a VS solution to make it work, and the CodeLab output source looks fine.


Full error message: PaintDotNet.WorkerThreadException: Worker thread threw an exception ---> System.NullReferenceException: Object reference not set to an instance of an object.

at PasswordProtectEffect.PasswordProtectEffectPlugin.Render(Surface dst, Surface src, Rectangle rect)

at PasswordProtectEffect.PasswordProtectEffectPlugin.OnRender(Rectangle[] rois, Int32 startIndex, Int32 length)

I can't find it.

Codelab source:

#region UICode
string Amount1 = "Password"; // Password

void Render(Surface dst, Surface src, Rectangle rect)
   byte[] hashValue;
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
   hashValue = getArray(selection);
   byte B, G, R, A;
   long offset;
   for (int j = rect.Top; j < rect.Bottom; j++)
       for (int i = rect.Left; i < rect.Right; i++)
           offset = 4*(selection.Width*(j-selection.Top)+(i-selection.Left));
           B = (byte)(src[i,j].B ^ hashValue[offset]);
           G = (byte)(src[i,j].G ^ hashValue[offset+1]);
           R = (byte)(src[i,j].R ^ hashValue[offset+2]);
           A = (byte)(src[i,j].A ^ hashValue[offset+3]);
           dst[i,j] = ColorBgra.FromBgra(B, G, R, A);
private string cachedAmount1 = string.Empty;
private long arrayLength;
private byte[] cachedArray;
public byte[] getArray(Rectangle selection)
   if(Amount1 == cachedAmount1)
       return cachedArray;
   arrayLength = selection.Width*selection.Height*4;
   byte[] ourArray = new byte[arrayLength]; // TAKE THAT, MEMORY!
   byte[] b;
   long iGo = arrayLength/64;
   System.Text.Encoding enc = new System.Text.ASCIIEncoding();
   for(int i = 0; i < iGo; i++)
       System.Security.Cryptography.HashAlgorithm hash = new System.Security.Cryptography.SHA512Managed();
       b = hash.ComputeHash(enc.GetBytes(Amount1+i.ToString()));
       b.CopyTo(ourArray, i*64);
   cachedArray = ourArray;
   cachedAmount1 = Amount1;        
   return ourArray;

And getArray() is fine.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...