Click here to Skip to main content
15,905,508 members
Home / Discussions / C#
   

C#

 
AnswerRe: Voice conference using socket [modified] Pin
Deresen23-Feb-09 1:49
Deresen23-Feb-09 1:49 
GeneralRe: Voice conference using socket Pin
EliottA23-Feb-09 2:45
EliottA23-Feb-09 2:45 
GeneralRe: Voice conference using socket Pin
yesu prakash1-Mar-09 19:09
yesu prakash1-Mar-09 19:09 
GeneralRe: Voice conference using socket Pin
Deresen1-Mar-09 22:25
Deresen1-Mar-09 22:25 
GeneralRe: Voice conference using socket Pin
Gira Palmer3-Jun-11 3:40
Gira Palmer3-Jun-11 3:40 
QuestionHttpWebResponse timeout subsequently if I do not download the file but looking at the LastModified property only. Pin
Shao Voon Wong22-Feb-09 23:08
mvaShao Voon Wong22-Feb-09 23:08 
AnswerRe: HttpWebResponse timeout subsequently if I do not download the file but looking at the LastModified property only. Pin
Rob Philpott22-Feb-09 23:57
Rob Philpott22-Feb-09 23:57 
Questionan oaep padding error occured in asp.net Pin
venki5422-Feb-09 22:55
venki5422-Feb-09 22:55 
hi guys i am using a c# class file in asp.net this class file is rsacryptography class file for encoding and decoding


here is the class file



using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Collections;

namespace Cryptography
{
public class AsymmetricCryptography
{
// Fields
private string pk;
private string prk;

// Methods
public AsymmetricCryptography()
{
RSACryptoServiceProvider provider = new RSACryptoServiceProvider(0x400);
this.prk = provider.ToXmlString(true);
this.pk = provider.ToXmlString(false);
}

public static string Decript(string Decript_Text, string Private_Key)
{
string str = Decript_Text;
string str2 = "";
string xmlString = Private_Key;
RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
// RSAParameters parameters = new RSAParameters();
provider.FromXmlString(xmlString);
string str4 = "";
Queue queue = new Queue();
while (str.Length != 0)
{
if (provider.KeySize == 0x400)
{
str4 = str.Substring(0, str.IndexOf("=") + 1);
queue.Enqueue(str4);
str = str.Remove(0, str4.Length);
}
else
{
str4 = str.Substring(0, str.IndexOf("==") + 2);
queue.Enqueue(str4);
str = str.Remove(0, str4.Length);
}
}
queue.TrimToSize();
int count = queue.Count;
for (int i = 1; i <= count; i++)
{
str4 = (string)queue.Dequeue();
ERROR str2 = str2 + Encoding.ASCII.GetString(provider.Decrypt(Convert.FromBase64String(str4), true));
}
return str2;
}

public static string Encript(string Plain_Text, string Public_Key)
{
string str = Plain_Text;
string xmlString = Public_Key;
string str3 = "";
RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
//RSAParameters parameters = new RSAParameters();
provider.FromXmlString(xmlString);
int num = (str.Length / 0x20) + 1;
char[] chars = str.ToCharArray();
byte[][] bufferArray = new byte[num][];
int index = 0;
for (int i = 1; i <= num; i++)
{
if (i == num)
{
bufferArray[i - 1] = Encoding.ASCII.GetBytes(chars, index, chars.Length - index);
}
else
{
bufferArray[i - 1] = Encoding.ASCII.GetBytes(chars, index, 0x20);
index += 0x20;
}
}
string str4 = str;
for (int j = 0; j < bufferArray.Length; j++)
{
str3 = str3 + Convert.ToBase64String(provider.Encrypt(bufferArray[j], true));
}
return str3;
}

// Properties
public string Private_Key
{
get
{
return this.prk;
}
set
{
if (value != null)
{
this.prk = value;
}
}
}

public string Public_Key
{
get
{
return this.pk;
}
set
{
if (value != null)
{
this.pk = value;
}
}
}
}
public class HashCalculate
{
// Methods
public HashCalculate()
{}
public static string HashMD5(byte[] file)
{
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
byte[] buffer = file;
byte[] inArray = provider.ComputeHash(buffer);
provider.Clear();
return Convert.ToBase64String(inArray);
}
}
public class SymetricCryptography
{
public SymetricCryptography()
{
}
// Fields
private SymmetricAlgorithm mCSP = new DESCryptoServiceProvider();

// Methods
public byte[] DecryptFile(byte[] file)
{
ICryptoTransform transform = this.mCSP.CreateDecryptor(this.mCSP.Key, this.mCSP.IV);
byte[] buffer = file;
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
stream2.Write(buffer, 0, buffer.Length);
stream2.FlushFinalBlock();
stream2.Close();
return stream.ToArray();
}

public string DecryptString(string Value)
{
ICryptoTransform transform = this.mCSP.CreateDecryptor(this.mCSP.Key, this.mCSP.IV);
byte[] buffer = Convert.FromBase64String(Value);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
stream2.Write(buffer, 0, buffer.Length);
stream2.FlushFinalBlock();
stream2.Close();
return Encoding.UTF8.GetString(stream.ToArray());
}

public byte[] EncryptFile(byte[] file)
{
ICryptoTransform transform = this.mCSP.CreateEncryptor(this.mCSP.Key, this.mCSP.IV);
byte[] buffer = file;
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
stream2.Write(buffer, 0, buffer.Length);
stream2.FlushFinalBlock();
stream2.Close();
return stream.ToArray();
}

public string EncryptString(string Value)
{
ICryptoTransform transform = this.mCSP.CreateEncryptor(this.mCSP.Key, this.mCSP.IV);
byte[] bytes = Encoding.UTF8.GetBytes(Value);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
stream2.Write(bytes, 0, bytes.Length);
stream2.FlushFinalBlock();
stream2.Close();
return Convert.ToBase64String(stream.ToArray());
}

public string Initialization_Vector
{
get
{
this.mCSP.GenerateIV();
return Convert.ToBase64String(this.mCSP.IV);
}
set
{
if (value != null)
{
this.mCSP.IV = Convert.FromBase64String(value);
}
}
}

public string Sessio_Key
{
get
{
this.mCSP.GenerateKey();
return Convert.ToBase64String(this.mCSP.Key);
}
set
{
if (value != null)
{
this.mCSP.Key = Convert.FromBase64String(value);
}
}
}
}




}


this is the class file error is in this line


str2 = str2 + Encoding.ASCII.GetString(provider.Decrypt(Convert.FromBase64String(str4), true));



so guys plz help me to get out of this problems
with regards
venkatesh
QuestionHello ,Pls help me ,How to retrieve image from database (sqlserver 2005) to imabe button?(Asp.net c#+) [modified] Pin
muhammadafsal22-Feb-09 22:50
muhammadafsal22-Feb-09 22:50 
AnswerRe: Hello ,Pls help me ,How to retrieve image from database (sqlserver 2005) to imabe button?(Asp.net c#+) Pin
Calin Tatar23-Feb-09 0:21
Calin Tatar23-Feb-09 0:21 
GeneralRe: Hello ,Pls help me ,How to retrieve image from database (sqlserver 2005) to imabe button?(Asp.net c#+) Pin
muhammadafsal23-Feb-09 0:36
muhammadafsal23-Feb-09 0:36 
GeneralRe: Hello ,Pls help me ,How to retrieve image from database (sqlserver 2005) to imabe button?(Asp.net c#+) Pin
Calin Tatar23-Feb-09 0:39
Calin Tatar23-Feb-09 0:39 
Questionremote access to sql server 2000 Pin
H.R22-Feb-09 22:44
H.R22-Feb-09 22:44 
AnswerRe: remote access to sql server 2000 Pin
Vimalsoft(Pty) Ltd22-Feb-09 22:52
professionalVimalsoft(Pty) Ltd22-Feb-09 22:52 
AnswerRe: remote access to sql server 2000 Pin
yeminkyi22-Feb-09 22:57
yeminkyi22-Feb-09 22:57 
QuestionReporting Pin
yeminkyi22-Feb-09 22:44
yeminkyi22-Feb-09 22:44 
AnswerRe: Reporting Pin
yeminkyi22-Feb-09 22:47
yeminkyi22-Feb-09 22:47 
GeneralRe: Reporting Pin
Calin Tatar22-Feb-09 23:47
Calin Tatar22-Feb-09 23:47 
AnswerRe: Reporting Pin
Rafone23-Feb-09 1:25
Rafone23-Feb-09 1:25 
QuestionHow to add reference to some com object in run time ? Pin
Yanshof22-Feb-09 22:42
Yanshof22-Feb-09 22:42 
AnswerRe: How to add reference to some com object in run time ? Pin
ABitSmart22-Feb-09 23:14
ABitSmart22-Feb-09 23:14 
Questiondetect mass storage devices Pin
Jassim Rahma22-Feb-09 21:57
Jassim Rahma22-Feb-09 21:57 
AnswerRe: detect mass storage devices Pin
Christian Graus22-Feb-09 21:58
protectorChristian Graus22-Feb-09 21:58 
GeneralRe: detect mass storage devices Pin
Jassim Rahma22-Feb-09 22:26
Jassim Rahma22-Feb-09 22:26 
QuestionA Question About MSMQ(Microsoft Message Queue) Pin
Jason_Shen22-Feb-09 21:45
Jason_Shen22-Feb-09 21:45 

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.