Skip to content

Commit 6fea326

Browse files
committed
append/remove last(null) byte
1 parent b6c22aa commit 6fea326

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

SPHDecode/Implementations/util.cs

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Xml;
1+
using System;
2+
using System.Xml;
23

34
namespace SPHDecode.Implementations
45
{
@@ -26,5 +27,31 @@ public static bool IsValidXML(string value)
2627
return false;
2728
}
2829
}
30+
31+
public static byte[] removeNullByte (byte[] data)
32+
{
33+
if (data[data.Length - 1].Equals(0))
34+
{
35+
byte[] tmp = new byte[data.Length - 1];
36+
Array.Copy(data, tmp, data.Length - 1);
37+
38+
return tmp;
39+
}
40+
41+
return data;
42+
}
43+
44+
public static byte[] addNullByte (byte[] data)
45+
{
46+
if (data[data.Length - 1].Equals(0).Equals(false))
47+
{
48+
byte[] tmp = data;
49+
Array.Resize(ref tmp, tmp.Length + 1);
50+
51+
return tmp;
52+
}
53+
54+
return data;
55+
}
2956
}
3057
}

SPHDecode/Model/MainWindowModel.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void OndstFileDialogExecute()
7272
private void OnencryptExecute()
7373
{
7474
byte[] orig = File.ReadAllBytes(srcFile);
75-
byte[] encode = Cryptography.Encrypt(orig);
75+
byte[] encode = Cryptography.Encrypt(util.addNullByte(orig));
7676

7777
if (Object.Equals(encode, null).Equals(false))
7878
{
@@ -84,7 +84,7 @@ private void OnencryptExecute()
8484
private void OndecryptExecute()
8585
{
8686
byte[] orig = File.ReadAllBytes(srcFile);
87-
byte[] decode = Cryptography.Decrypt(orig);
87+
byte[] decode = util.removeNullByte(Cryptography.Decrypt(orig));
8888

8989
if (Object.Equals(decode, null).Equals(false))
9090
{

0 commit comments

Comments
 (0)