Skip to content

Commit

Permalink
append/remove last(null) byte
Browse files Browse the repository at this point in the history
  • Loading branch information
Stricted committed Jan 27, 2016
1 parent b6c22aa commit 6fea326
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
29 changes: 28 additions & 1 deletion SPHDecode/Implementations/util.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Xml;
using System;
using System.Xml;

namespace SPHDecode.Implementations
{
Expand Down Expand Up @@ -26,5 +27,31 @@ public static bool IsValidXML(string value)
return false;
}
}

public static byte[] removeNullByte (byte[] data)
{
if (data[data.Length - 1].Equals(0))
{
byte[] tmp = new byte[data.Length - 1];
Array.Copy(data, tmp, data.Length - 1);

return tmp;
}

return data;
}

public static byte[] addNullByte (byte[] data)
{
if (data[data.Length - 1].Equals(0).Equals(false))
{
byte[] tmp = data;
Array.Resize(ref tmp, tmp.Length + 1);

return tmp;
}

return data;
}
}
}
4 changes: 2 additions & 2 deletions SPHDecode/Model/MainWindowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void OndstFileDialogExecute()
private void OnencryptExecute()
{
byte[] orig = File.ReadAllBytes(srcFile);
byte[] encode = Cryptography.Encrypt(orig);
byte[] encode = Cryptography.Encrypt(util.addNullByte(orig));

if (Object.Equals(encode, null).Equals(false))
{
Expand All @@ -84,7 +84,7 @@ private void OnencryptExecute()
private void OndecryptExecute()
{
byte[] orig = File.ReadAllBytes(srcFile);
byte[] decode = Cryptography.Decrypt(orig);
byte[] decode = util.removeNullByte(Cryptography.Decrypt(orig));

if (Object.Equals(decode, null).Equals(false))
{
Expand Down

0 comments on commit 6fea326

Please sign in to comment.