
Sometimes you may need to use encryption and decryption class in your C# project. Here is a simple class you can use for above purpose feel free to use it and feedback with improvement. This class use Advance Encryption Standers. and RijndaelManaged method.
/*******************************************************************
File: Crypter.cs
Author: Nayana Adassuriya
Description: Uses to encrypt or decrypt any string by symettric way (AES,RijndaelManaged)
Language: C#
Limitations: Encription key genaration hashes are hardcoded in the class.
If some one knows these hashes, they can crate programe to decript the encripted strings.
Thread Safe: no
Extendable: yes
Platform Depend: Windows,.NET 3.5
Project: None
*******************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace StorageService
{
internal class Crypter
{
//Data members
private static byte[] m_salt = Encoding.ASCII.GetBytes("41fb5b5ae4d57c5ee528adb00e5e8e74");
private static string m_encrypt_key = "200911381f7899d2482ab61fe8d15684469b17fc690";
/************************************************************************
Purpose : This is the method uses to encrypt plan strings.
Parameters : plan_test: text that need to be encrypted
Returns : encrypted string
Exception : If any exception while getting values from xml, pass to the upper level
Algorithm : C# manage code
Output : None
Notes : User can encrypt multiple times recursively if more security needs. If that
need to decrypt same number of rounds accordingly
*************************************************************************/
internal static string aesEncrypt(string plan_test)
{
string output = null;
RijndaelManaged aes_alg = null;
try
{
Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(m_encrypt_key, m_salt);
aes_alg = new RijndaelManaged();
aes_alg.Key = key.GetBytes(aes_alg.KeySize / 8);
ICryptoTransform encryptor = aes_alg.CreateEncryptor(aes_alg.Key, aes_alg.IV);
using (MemoryStream encrypt_ms = new MemoryStream())
{
encrypt_ms.Write(BitConverter.GetBytes(aes_alg.IV.Length), 0, sizeof(int));
encrypt_ms.Write(aes_alg.IV, 0, aes_alg.IV.Length);
using (CryptoStream encrypt_cs = new CryptoStream(encrypt_ms, encryptor, CryptoStreamMode.Write))
{
using (StreamWriter encrypt_sw = new StreamWriter(encrypt_cs))
{
encrypt_sw.Write(plan_test);
}
}
output = Convert.ToBase64String(encrypt_ms.ToArray());
}
}
catch (Exception e)
{
throw e;
}
finally
{
if (aes_alg != null)
{
aes_alg.Clear();
}
}
return output;
}
/************************************************************************
Purpose : This is the method uses to decrypt the encrypted strings.
Parameters : cipher_text: decrypted string need to decrypt to plan text
Returns : Plan text after decrypted
Exception : If any exception while getting values from xml, pass to the upper level
Algorithm : C# manage code
Output : None
Notes : User can encrypt multiple times recursively if more security needs. If
that need to decrypt same number of rounds accordingly.
*************************************************************************/
internal static string aesDecrypt(string cipher_text)
{
RijndaelManaged aes_alg = null;
string plain_text = null;
try
{
Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(m_encrypt_key, m_salt);
byte[] bytes = Convert.FromBase64String(cipher_text);
using (MemoryStream decrypt_ms = new MemoryStream(bytes))
{
aes_alg = new RijndaelManaged();
aes_alg.Key = key.GetBytes(aes_alg.KeySize / 8);
aes_alg.IV = ReadByteArray(decrypt_ms);
ICryptoTransform decryptor = aes_alg.CreateDecryptor(aes_alg.Key, aes_alg.IV);
using (CryptoStream decrypt_cs = new CryptoStream(decrypt_ms, decryptor, CryptoStreamMode.Read))
{
using (StreamReader decrypt_sr = new StreamReader(decrypt_cs))
plain_text = decrypt_sr.ReadToEnd();
}
}
}
catch (Exception e)
{
throw e;
}
finally
{
if (aes_alg != null)
aes_alg.Clear();
}
return plain_text;
}
/************************************************************************
Purpose : Use to read first few bytes from cipher string( this helps to generate
the same key used in encrypt method again)
Parameters : stream: stream that use to read the cipher text bytes from memory.
Returns : return byte array filled with first few bytes of the cipher string.
Exception : If any exception while getting values from xml, pass to the upper level
Algorithm : C# manage code
Output : None
Notes : None
*************************************************************************/
private static byte[] ReadByteArray(Stream stream)
{
byte[] buffer;
byte[] row_length = new byte[sizeof(int)];
try
{
if (stream.Read(row_length, 0, row_length.Length) != row_length.Length)
{
throw new SystemException("encrypted string not contain properly formatted byte array");
}
int temp = BitConverter.ToInt32(row_length, 0);
buffer = new byte[temp];
if (stream.Read(buffer, 0, buffer.Length) != buffer.Length)
{
throw new SystemException("Did not read encrypted string properly");
}
}
catch (Exception e)
{
throw e;
}
return buffer;
}
}
}
hank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me
ReplyDeleteData science training in Bangalore
Data Science training in marathahalli
Data Science training in btm
Data Science training in rajaji nagar
Data Science training in chennai
Data Science training in kalyan nagar
Data Science training in electronic city
Data Science training in USA
IEEE Final Year Project centers make amazing deep learning final year projects ideas for final year students Final Year Projects for CSE to training and develop their deep learning experience and talents.
DeleteIEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation.
corporate training in chennai corporate training in chennai
corporate training companies in india corporate training companies in india
corporate training companies in chennai corporate training companies in chennai
I have read your blog its very attractive and impressive. I like it your blog. Digital Marketing Company in Chennai
Wonderful article, very useful and well explanation. Your post is extremely incredible. I will refer this to my candidates...
ReplyDeletejava training in chennai | java training in bangalore
java training in tambaram | java training in velachery
java training in omr | oracle training in chennai
Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
ReplyDeleteAWS Training in Bangalore | Amazon Web Services Training in Bangalore
Amazon Web Services Training in Pune | Best AWS Training in Pune
AWS Online Training | Online AWS Certification Course - Gangboard
Selenium Training in Chennai | Best Selenium Training in Chennai
Selenium Training in Bangalore | Best Selenium Training in Bangalore
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
ReplyDeletepython training in rajajinagar
Python training in btm
Python training in usa
Thank you for excellent article.
ReplyDeletePlease refer below if you are looking for best project center in coimbatore
final year projects in coimbatore
Spoken English Training in coimbatore
final year projects for CSE in coimbatore
final year projects for IT in coimbatore
final year projects for ECE in coimbatore
final year projects for EEE in coimbatore
final year projects for Mechanical in coimbatore
final year projects for Instrumentation in coimbatore
I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing.
ReplyDeleteBecame an Expert In Google Cloud Platform Training in Bangalore! Learn from experienced Trainers and get the knowledge to crack a coding interview, @Softgen Infotech Located in BTM Layout.
very nice post...
ReplyDeleteinplant training in chennai
inplant training in chennai
inplant training in chennai for it.php
Australia hosting
mexico web hosting
moldova web hosting
albania web hosting
andorra hosting
australia web hosting
denmark web hosting
Hats off to your presence of mind...I really enjoyed reading your blog. I really appreciate your information which you shared with us.
ReplyDeleteBest SAP Training in Bangalore
Best SAP ABAP Training in Bangalore
Best SAP BASIS Training in Bangalore
Best SAP FICO Training in Bangalore
Best SAP MM Training in Bangalore
Best SAP SD Training in Bangalore
Best SAP HR HCM Training in Bangalore
Such a great word which you use in your article and article is amazing knowledge. thank you for sharing it.
ReplyDeleteBest SAP Training in Bangalore
Best SAP ABAP Training in Bangalore
Best SAP FICO Training in Bangalore
Best SAP HANA Training in Bangalore
Best SAP MM Training in Bangalore
Best SAP SD Training in Bangalore
Really i appreciate the effort you made to share the knowledge. The topic here i found was really effective...
ReplyDeleteBest SAP HR Training in Bangalore
Best SAP BASIS Training in Bangalore
Best SAP HCM Training in Bangalore
Best SAP S4 HANA Simple Finance Training in Bangalore
Best SAP S4 HANA Simple Logistics Training in Bangalore
nice...................
ReplyDeleteinplant training in chennai
inplant training in chennai
inplant training in chennai for it
algeeria hosting
angola hostig
shared hosting
bangladesh hosting
botswana hosting
central african republi hosting
shared hosting
Very Nice...
ReplyDeleteinternship in chennai for ece students with stipend
internship for mechanical engineering students in chennai
inplant training in chennai
free internship in pune for computer engineering students
internship in chennai for mca
iot internships
internships for cse students in
implant training in chennai
internship for aeronautical engineering students in bangalore
inplant training certificate
ReplyDeletegood.....
kaashiv infotech pune
industrial training report for electronics and communication
internships for cse
internship for automobile engineering students in bangalore
internships in bangalore for eee students
internship for civil engineering students in chennai 2019
internship in automobile companies in chennai
robotics chennai
final year projects for information technology
Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
ReplyDeleteOracle Training | Online Course | Certification in chennai | Oracle Training | Online Course | Certification in bangalore | Oracle Training | Online Course | Certification in hyderabad | Oracle Training | Online Course | Certification in pune | Oracle Training | Online Course | Certification in coimbatore
Wondering where to get an Online Matlab Tutor? At Matlab Assignment Help, we offer timely classes for all Matlab students in need. Other than the tuition classes, we also complete your assignments ensuring that you get the top grade in your class. Our prices are fair because we understand that most students don’t have a source of income. However, the fair price does not mean the quality of work is compromised. Visit our website “ Matlab Homework Help”today and talk to an expert.
ReplyDeleteMy control systems solution was great but unfortunately, it was delivered a day after the deadline. I took Matlab assignment help from here because I had read some really good reviews about MatlabAssignmentExperts and especially where the customers were happy about their assignments being delivered on time and sometimes even a few days before the deadline. I had a totally different experience and the only reason I was able to beat my deadline was that I had given the Matlab assignment helperwho handled my task the wrong deadline. Still, the platform isn’t so bad because I got a decent grade from the solution they prepared but they should address the late delivery issue asap.
ReplyDeleteIf your work is not satisfactory do you have a complaint center or what happens when I need a task re-done? There are times when assignments need revision and I would like to know what process is followed in your website when seeking a revision. I need economics assignment help and that is why I am seeking clarification. You can complete it or get me an economics homework help expert from your website. Provided the work is quality I will have no issues.
ReplyDeleteSharing the same interest, Infycle feels so happy to share our detailed information about all these courses with you all! Do check them out
ReplyDeleteoracle training in chennai & get to know everything you want to about software trainings.
Lucky Bird Casino: kasyno online z licencjÄ…: recenzja, bonusy , recenzje - https://top10casinoexpert.pl/casino/lucky-bird-casino/
ReplyDeleteFinish the Big Data Certification in Chennai from Infycle Technologies, the best software training institute in Chennai which is providing professional software courses such as Data Science, Artificial Intelligence, Java, Hadoop, Selenium, Android, and iOS Development, etc with 100% hands-on practical training. Dial 7502633633 to get more info and a free demo and to grab the certification for having a peak rise in your career.Get Big Data Certification in Chennai | Infycle Technologies
ReplyDeleteFinish the Selenium Training in Chennai from Infycle Technologies, the best software training institute in Chennai which is providing professional software courses such as Data Science, Artificial Intelligence, Java, Hadoop, Big Data, Android, and iOS Development, Oracle, etc with 100% hands-on practical training. Dial 7502633633 to get more info and a free demo and to grab the certification for having a peak rise in your career.
ReplyDeleteInfycle Technologies, one of the topmost software training institutes in Chennai offers excellent Oracle PLSQL training in Chennai for freshers and students, and Tech Professionals of any field. Other demanding courses such as Digital Marketing, Java, Python, Hadoop, Selenium, Big Data, AWS, Android, and iOS Development will also be trained with complete hands-on training. After the completion of training, the students will be sent for placement interviews in the core MNC's. Dial 7504633633 to get more info and a free demo.Excellent Oracle PLSQL Training Chennai | Infycle Technologies
ReplyDeleteInfycle Technologies, the No.1 software training institute in Chennai offers the No.1 Big Data Hadoop Training in Chennai | Infycle Technologies for students, freshers, and tech professionals. Infycle also offers other professional courses such as DevOps, Artificial Intelligence, Cyber Security, Python, Oracle, Java, Power BI, Selenium Testing, Digital Marketing, Data Science, etc., which will be trained with 200% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7502633633 to get more info and a free demo.
ReplyDeleteFinish the Get Big Data Certification in Chennai from Infycle Technologies, the best software training institute in Chennai which is providing professional software courses such as Data Science, Artificial Intelligence, Java, Hadoop, Selenium, Android, and iOS Development, etc with 100% hands-on practical training. Dial 7502633633 to get more info and a free demo and to grab the certification for having a peak rise in your career.
ReplyDeleteSuperb blog and great post.Its truly supportive for me, anticipating for all the more new post. Continue Blogging!
ReplyDeleteBiotech Internships | internships for cse students | web designing course in chennai | it internships | electrical engineering internships | internship for bcom students | python training in chennai | web development internship | internship for bba students | internship for 1st year engineering students