TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Samia Souror
NA
33
5.2k
What is the problem of increasing time encryption Algorithm?
Feb 21 2019 4:02 PM
I have my own stream cipher algorithm, and I made a comparison between it and AES performance. I tested it on several files with different sizes(to 500KB). Its encryption/decryption time is less than AES for files about 500KB. but with files more than 500KB, its encryption time is more than AES but still its decryption time is the least one.
public
static
byte
[] AES_Encrypt(
byte
[] bytesToBeEncrypted,
byte
[] passwordBytes)
{
byte
[] encryptedBytes =
null
;
byte
[] saltBytes =
new
byte
[] { 1, 2, 3, 4, 5, 6, 7, 8 };
using
(MemoryStream ms =
new
MemoryStream())
{
using
(RijndaelManaged AES =
new
RijndaelManaged()) {
AES.KeySize = 128;
AES.BlockSize = 128;
var key =
new
Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Padding = PaddingMode.Zeros;
AES.Mode = CipherMode.CFB;
using
(var cs =
new
CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
{ cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
cs.Close();
} encryptedBytes = ms.ToArray();
}
ms.Close();
}
return
encryptedBytes;
}
public
static
byte
[] AES_Decrypt(
byte
[] bytesToBeDecrypted,
byte
[] passwordBytes)
{
byte
[] decryptedBytes =
null
;
byte
[] saltBytes =
new
byte
[] { 1, 2, 3, 4, 5, 6, 7, 8 };
using
(MemoryStream ms =
new
MemoryStream())
{
using
(RijndaelManaged AES =
new
RijndaelManaged())
{ AES.KeySize = 128;
AES.BlockSize = 128;
var key =
new
Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Padding = PaddingMode.Zeros;
AES.Mode = CipherMode.CFB;
using
(var cs =
new
CryptoStream(ms,AES.CreateDecryptor(), CryptoStreamMode.Write))
{ cs.Write(bytesToBeDecrypted, 0, bytesToBeDecrypted.Length);
cs.Close(); }
decryptedBytes = ms.ToArray();
} }
return
decryptedBytes; }
My encryption algorithm
public
static
byte
[] Encrypt(
byte
[] PlainTextBytes,
byte
[] KeyHashBytes)
{ StringBuilder Builder =
new
StringBuilder();
for
(
int
i = 0; i < KeyHashBytes.Length; i++)
{ Builder.Append(KeyHashBytes[i].ToString(
"x2"
)); }
String KeyHashString = Builder.ToString();
Byte[] LeftHash = Encoding.ASCII.GetBytes(KeyHashString.Substring(0, 16));
Byte[] RightHash = Encoding.ASCII.GetBytes(KeyHashString.Substring(16));
Byte[] MappingData =
new
Byte[PlainTextBytes.Length];
Byte[] EncryptedBytes =
new
Byte[PlainTextBytes.Length * 2];
for
(
int
i = 0; i < PlainTextBytes.Length; i++)
{
int
PlainInteger = Convert.ToInt32(PlainTextBytes[i]);
bool
Left = (PlainInteger % 2 == 0);
int
MappingIndex = (PlainInteger % 16);
PlainTextBytes[i] = (
byte
)((Left) ? (PlainTextBytes[i] ^ LeftHash[MappingIndex]) : (PlainTextBytes[i] ^ RightHash[MappingIndex]));
int
PlainByteInteger = (
int
)PlainTextBytes[i];
PlainTextBytes[i] = (
byte
)(Math.Floor(((
double
) (PlainByteInteger) / 2)) + 33);
MappingData [i] = (
byte
)(MappingIndex + ((Left) ? 0 : 16));
MappingData [i] = (
byte
)((((PlainByteInteger) % 2 == 1)) ? ((
int
)MappingData [i]) + 32 : ((
int
)MappingData [i]) + 0);
MappingData [i] = (
byte
)(((
int
)MappingData [i]) + 33);
EncryptedBytes[i * 2] = PlainTextBytes[i];
EncryptedBytes[i * 2 + 1] = MappingData [i];
}
return
EncryptedBytes;
}
private
void
Encrypt_Click(
object
sender, EventArgs e)
{
string
password1 = textPassword.ToString();
string
password2 = textVerifiedPassword.ToString();
if
(password1 == password2 && fileName !=
null
)
{
byte
[] bytesToBeEncrypted = File.ReadAllBytes(fileName);
byte
[] passwordBytes = Encoding.UTF8.GetBytes(password1);
byte
[] PwdHash = MD5.Create().ComputeHash(passwordBytes);
byte
[] bytesEncrypted = AES.AES_Encrypt(bytesToBeEncrypted, PwdHash);
byte
[] bytesEncrypted = AES.AES_Decrypt(bytesToBeEncrypted, PwdHash);
byte
[] bytesEncrypted = SCKSA.Encrypt(bytesToBeEncrypted, PwdHash);
byte
[] bytesEncrypted = SCKSA.Decrypt(bytesToBeEncrypted, PwdHash); }}
Reply
Answers (
1
)
How can I get this 6 for loop done with recursive programmin
AES encryption C# cipher text length