Click here to Skip to main content
15,901,853 members
Home / Discussions / C#
   

C#

 
GeneralSteal Information from another website(Or say anything) Pin
Member 366988919-Feb-09 23:56
Member 366988919-Feb-09 23:56 
GeneralRe: Steal Information from another website(Or say anything) Pin
Eddy Vluggen20-Feb-09 0:02
professionalEddy Vluggen20-Feb-09 0:02 
GeneralRe: Steal Information from another website(Or say anything) Pin
Tony Pottier20-Feb-09 1:32
Tony Pottier20-Feb-09 1:32 
GeneralRe: Steal Information from another website(Or say anything) Pin
PIEBALDconsult20-Feb-09 3:47
mvePIEBALDconsult20-Feb-09 3:47 
QuestionError Throwing options-Suggestions please Pin
Ramkithepower19-Feb-09 23:52
Ramkithepower19-Feb-09 23:52 
AnswerRe: Error Throwing options-Suggestions please Pin
Ramkithepower19-Feb-09 23:54
Ramkithepower19-Feb-09 23:54 
AnswerRe: Error Throwing options-Suggestions please Pin
moon_stick20-Feb-09 1:38
moon_stick20-Feb-09 1:38 
Questionoaep padding error in asp.net while decrypting a string Pin
venki5419-Feb-09 23:46
venki5419-Feb-09 23:46 
this is a c# class file to encrypt/decrypt

a string when i am using this code in asp.net i am getting an error saying "an error occured in oaep padding" so plz guys help me to get out of this error

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();
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);
}
}
}
}
AnswerRe: oaep padding error in asp.net while decrypting a string Pin
Henry Minute20-Feb-09 0:21
Henry Minute20-Feb-09 0:21 
AnswerRe: oaep padding error in asp.net while decrypting a string Pin
DaveyM6920-Feb-09 2:06
professionalDaveyM6920-Feb-09 2:06 
Questionproblem bringing over fullpath or parent nodes(files/folders) when drag/dropping from one TreeView to another Pin
fabgar19-Feb-09 23:31
fabgar19-Feb-09 23:31 
AnswerRe: problem bringing over fullpath or parent nodes(files/folders) when drag/dropping from one TreeView to another Pin
Henry Minute20-Feb-09 0:30
Henry Minute20-Feb-09 0:30 
GeneralRe: problem bringing over fullpath or parent nodes(files/folders) when drag/dropping from one TreeView to another Pin
fabgar20-Feb-09 3:15
fabgar20-Feb-09 3:15 
GeneralRe: problem bringing over fullpath or parent nodes(files/folders) when drag/dropping from one TreeView to another Pin
Henry Minute20-Feb-09 3:28
Henry Minute20-Feb-09 3:28 
GeneralRe: problem bringing over fullpath or parent nodes(files/folders) when drag/dropping from one TreeView to another Pin
fabgar20-Feb-09 3:57
fabgar20-Feb-09 3:57 
GeneralRe: problem bringing over fullpath or parent nodes(files/folders) when drag/dropping from one TreeView to another Pin
Henry Minute20-Feb-09 4:02
Henry Minute20-Feb-09 4:02 
QuestionDatagridview Performance Pin
Member 202517619-Feb-09 23:20
Member 202517619-Feb-09 23:20 
AnswerRe: Datagridview Performance Pin
Eddy Vluggen19-Feb-09 23:57
professionalEddy Vluggen19-Feb-09 23:57 
QuestionHow to change value of "Combobox.MaxDropDownItems" Pin
abhiram_nayan19-Feb-09 22:45
abhiram_nayan19-Feb-09 22:45 
AnswerRe: How to change value of "Combobox.MaxDropDownItems" Pin
musefan19-Feb-09 23:31
musefan19-Feb-09 23:31 
AnswerRe: How to change value of "Combobox.MaxDropDownItems" Pin
GihanChandima9-Jan-11 19:25
GihanChandima9-Jan-11 19:25 
QuestionParameter is not valid (with bitmap) Pin
Matjaz-xyz19-Feb-09 22:36
Matjaz-xyz19-Feb-09 22:36 
AnswerRe: Parameter is not valid (with bitmap) Pin
Henry Minute20-Feb-09 0:53
Henry Minute20-Feb-09 0:53 
QuestionScroll tableLayoutPanel Pin
anishkannan19-Feb-09 21:54
anishkannan19-Feb-09 21:54 
AnswerRe: Scroll tableLayoutPanel Pin
Henry Minute20-Feb-09 0:39
Henry Minute20-Feb-09 0:39 

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.