Click here to Skip to main content
15,889,876 members
Home / Discussions / C#
   

C#

 
AnswerRe: Xml special character Pin
12Code28-Apr-09 21:44
12Code28-Apr-09 21:44 
AnswerRe: Xml special character Pin
Jimmanuel29-Apr-09 1:10
Jimmanuel29-Apr-09 1:10 
AnswerRe: Xml special character Pin
Soundman32.229-Apr-09 2:20
Soundman32.229-Apr-09 2:20 
QuestionI have a problem with Convert.FromBase64String Pin
Roshanakak28-Apr-09 21:06
Roshanakak28-Apr-09 21:06 
AnswerRe: I have a problem with Convert.FromBase64String Pin
CPallini28-Apr-09 21:34
mveCPallini28-Apr-09 21:34 
AnswerRe: I have a problem with Convert.FromBase64String Pin
12Code28-Apr-09 21:40
12Code28-Apr-09 21:40 
AnswerRe: I have a problem with Convert.FromBase64String Pin
J a a n s28-Apr-09 21:59
professionalJ a a n s28-Apr-09 21:59 
GeneralRe: I have a problem with Convert.FromBase64String Pin
Roshanakak28-Apr-09 22:13
Roshanakak28-Apr-09 22:13 
I'm trying to encrypt sth, and those lines were just a part of my code. I'm sorry for not being clear but i wanted to be brief,
this is the whole code:
<br />
using System;<br />
using System.IO;<br />
using System.Text;<br />
using System.Security.Cryptography;<br />
<br />
namespace Cryptography<br />
{<br />
   <br />
    public sealed class Cryption<br />
    {<br />
        private RijndaelManaged Algorithm;<br />
<br />
        private string m_key;<br />
        private string m_iv;<br />
<br />
        private byte[] key;<br />
        private byte[] iv;<br />
<br />
<br />
<br />
        public Cryption(string key_val, string iv_val)<br />
        {<br />
            key = new byte[32];<br />
            iv = new byte[32];<br />
<br />
            int i;<br />
            m_key = key_val;<br />
            m_iv = iv_val;<br />
<br />
            for (i = 0; i < m_key.Length; i++)<br />
            {<br />
                key[i] = Convert.ToByte(m_key[i]);<br />
            }<br />
            for (i = 0; i < m_iv.Length; i++)<br />
            {<br />
                iv[i] = Convert.ToByte(m_iv[i]);<br />
            }<br />
<br />
        }<br />
<br />
<br />
        public string Encrypt(string s)<br />
        {<br />
            string enc_str;<br />
            byte[] enc_byte;<br />
<br />
            Algorithm = new RijndaelManaged();<br />
<br />
            Algorithm.BlockSize = 256;<br />
            Algorithm.KeySize = 256;<br />
            Algorithm.Padding = PaddingMode.PKCS7;<br />
<br />
<br />
            using (MemoryStream memStream = new MemoryStream())<br />
            {<br />
                using (ICryptoTransform EncryptorDecryptor = Algorithm.CreateEncryptor(key, iv))<br />
                {<br />
                    using (CryptoStream crStream = new CryptoStream(memStream, EncryptorDecryptor, CryptoStreamMode.Write))<br />
                    {<br />
                        UTF8Encoding utf8enc = new UTF8Encoding();<br />
                        enc_byte = utf8enc.GetBytes(s);<br />
                        crStream.Write(enc_byte, 0, enc_byte.Length);<br />
                        crStream.FlushFinalBlock();<br />
                    }<br />
                }<br />
            }<br />
<br />
<br />
            enc_str = Convert.ToBase64String(enc_byte);<br />
            return enc_str;<br />
<br />
        }<br />
<br />
<br />
<br />
        public string Decrypt(string s)<br />
        {<br />
            string dec_str;<br />
            //byte[] dec_byte;<br />
            byte[] decrepted_byte;<br />
<br />
            Algorithm = new RijndaelManaged();<br />
<br />
            Algorithm.BlockSize = 256;<br />
            Algorithm.KeySize = 256;<br />
            Algorithm.Padding = PaddingMode.PKCS7;<br />
<br />
<br />
            byte[] dec_byte = new byte[s.Length];<br />
            dec_byte = Convert.FromBase64String(s);<br />
            decrepted_byte = new byte[dec_byte.Length];<br />
<br />
            using (MemoryStream memStream = new MemoryStream(dec_byte))<br />
            {<br />
                using (ICryptoTransform EncryptorDecryptor = Algorithm.CreateDecryptor(key, iv))<br />
                {<br />
                    using (CryptoStream crStream = new CryptoStream(memStream, EncryptorDecryptor, CryptoStreamMode.Read))<br />
                    {<br />
                        crStream.Read(decrepted_byte, 0, decrepted_byte.Length);<br />
                    }<br />
                }<br />
            }<br />
<br />
            UTF8Encoding utf8enc = new UTF8Encoding();<br />
            dec_str = utf8enc.GetString(decrepted_byte);<br />
            return dec_str;<br />
<br />
        }<br />
<br />
    }<br />
}<br />



so, you see none of the answers could help me!
GeneralRe: I have a problem with Convert.FromBase64String Pin
Luc Pattyn28-Apr-09 23:56
sitebuilderLuc Pattyn28-Apr-09 23:56 
GeneralRe: I have a problem with Convert.FromBase64String Pin
J a a n s29-Apr-09 0:04
professionalJ a a n s29-Apr-09 0:04 
Questionunit testing function Pin
BabyOreo28-Apr-09 20:23
BabyOreo28-Apr-09 20:23 
AnswerRe: unit testing function Pin
SeMartens28-Apr-09 21:05
SeMartens28-Apr-09 21:05 
GeneralRe: unit testing function Pin
BabyOreo29-Apr-09 15:03
BabyOreo29-Apr-09 15:03 
GeneralRe: unit testing function Pin
SeMartens29-Apr-09 21:09
SeMartens29-Apr-09 21:09 
QuestionCapture network Video stream? Pin
IvanBeograd28-Apr-09 20:03
IvanBeograd28-Apr-09 20:03 
AnswerRe: Capture network Video stream? Pin
IvanBeograd5-May-09 14:10
IvanBeograd5-May-09 14:10 
QuestionNot able to receive data using tcp(urgent!) Pin
patra.santanu@yahoo.co.in28-Apr-09 19:56
patra.santanu@yahoo.co.in28-Apr-09 19:56 
Questionsave gridview values in database Pin
grkrishna28-Apr-09 19:10
grkrishna28-Apr-09 19:10 
AnswerRe: save gridview values in database PinPopular
grkrishna28-Apr-09 22:26
grkrishna28-Apr-09 22:26 
AnswerRe: save gridview values in database [modified] Pin
sorifazlu14-Sep-11 23:26
sorifazlu14-Sep-11 23:26 
Questionfind .lib, .dll in exe Pin
RKP72828-Apr-09 19:05
RKP72828-Apr-09 19:05 
AnswerRe: find .lib, .dll in exe Pin
RKP72828-Apr-09 19:06
RKP72828-Apr-09 19:06 
QuestionHow can I get the time taken for PDF getting downloaded when it is opened on Internet Explorer? Pin
svt gdwl28-Apr-09 18:19
svt gdwl28-Apr-09 18:19 
AnswerRe: How can I get the time taken for PDF getting downloaded when it is opened on Internet Explorer? Pin
_Maxxx_28-Apr-09 19:45
professional_Maxxx_28-Apr-09 19:45 
QuestionUnable to load DLL - Why ?? Pin
matty2desmara28-Apr-09 15:53
matty2desmara28-Apr-09 15:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.