Illnab1024 Posted November 4, 2009 Share Posted November 4, 2009 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. Error: 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 #endregion 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. Quote ~~ Link to comment Share on other sites More sharing options...
pyrochild Posted November 5, 2009 Share Posted November 5, 2009 ... public byte[] getArray(Rectangle selection) { if(cachedArray != null && Amount1 == cachedAmount1) { return cachedArray; } ... Fixed byte[] ourArray = new byte[arrayLength]; // TAKE THAT, MEMORY! Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
Illnab1024 Posted November 5, 2009 Author Share Posted November 5, 2009 Oh, right... I had thought about that halfway through before dismissing it-- CodeLab defines the default value for Amount1 in OnCreateConfigUI or whatnot as "" == string.Empty.. hooray for codelab? Quote ~~ Link to comment Share on other sites More sharing options...
pyrochild Posted November 5, 2009 Share Posted November 5, 2009 Hooray for Code Lab! Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.