Browse Source

Fixed bad encoding for paste encryption and storing.

tags/2.0.3
Teknikode 4 years ago
parent
commit
7b71a4bb5c

+ 2
- 2
Teknik/Areas/Paste/Controllers/PasteController.cs View File

@@ -54,7 +54,7 @@ namespace Teknik.Areas.Paste.Controllers
model.Syntax = paste.Syntax;
model.DatePosted = paste.DatePosted;

byte[] data = Encoding.Unicode.GetBytes(paste.Content);
byte[] data = Convert.FromBase64String(paste.Content);

// The paste has a password set
if (!string.IsNullOrEmpty(paste.HashedPassword))
@@ -71,7 +71,7 @@ namespace Teknik.Areas.Paste.Controllers
byte[] ivBytes = Encoding.Unicode.GetBytes(paste.IV);
byte[] keyBytes = AES.CreateKey(password, ivBytes, paste.KeySize);
data = AES.Decrypt(data, keyBytes, ivBytes);
model.Content = Convert.ToBase64String(data);
model.Content = Encoding.Unicode.GetString(data);
}

switch (type.ToLower())

+ 2
- 2
Teknik/Areas/Paste/PasteHelper.cs View File

@@ -59,7 +59,7 @@ namespace Teknik.Areas.Paste
if (!string.IsNullOrEmpty(password))
{
string key = Utility.RandomString(config.PasteConfig.KeySize / 8);
string iv = Utility.RandomString(config.PasteConfig.BlockSize / 8);
string iv = Utility.RandomString(config.PasteConfig.BlockSize / 16);
paste.HashedPassword = Helpers.SHA384.Hash(key, password);

// Encrypt Content
@@ -67,7 +67,7 @@ namespace Teknik.Areas.Paste
byte[] ivBytes = Encoding.Unicode.GetBytes(iv);
byte[] keyBytes = AES.CreateKey(password, ivBytes, config.PasteConfig.KeySize);
byte[] encData = AES.Encrypt(data, keyBytes, ivBytes);
content = Encoding.Unicode.GetString(encData);
content = Convert.ToBase64String(encData);

paste.Key = key;
paste.KeySize = config.PasteConfig.KeySize;

Loading…
Cancel
Save