Click here to Skip to main content
15,891,567 members
Home / Discussions / C#
   

C#

 
GeneralNew to C# Pin
parths1-Jul-03 0:09
parths1-Jul-03 0:09 
GeneralRe: New to C# Pin
Michael P Butler1-Jul-03 1:04
Michael P Butler1-Jul-03 1:04 
GeneralRe: New to C# Pin
james-cxx1-Jul-03 5:16
james-cxx1-Jul-03 5:16 
GeneralRe: New to C# Pin
parths1-Jul-03 16:23
parths1-Jul-03 16:23 
Generalstrange characters? how can i remove Pin
Asim N.30-Jun-03 22:50
Asim N.30-Jun-03 22:50 
GeneralRe: strange characters? how can i remove Pin
Philip Fitzsimons1-Jul-03 1:40
Philip Fitzsimons1-Jul-03 1:40 
GeneralRe: strange characters? how can i remove Pin
Asim N.2-Jul-03 22:50
Asim N.2-Jul-03 22:50 
GeneralHelp With Reading RSA Private Key From File (C#) Pin
yccheok30-Jun-03 21:56
yccheok30-Jun-03 21:56 
i face some problem in developing a simple file encryption/decryption by using RSA algorithm.
i fail to read private key from a file.

here is my portion of code in saving the private key:
------------------------------------------------------
private void WritePrivateKeyToFile(RSAParameters param, string fileName)
{
FileStream fs = File.Create(fileName);
fs.Write(param.P, 0, param.P.Length);
fs.Write(param.Q, 0, param.Q.Length);
fs.Write(param.D, 0, param.D.Length);
fs.Write(param.DP, 0, param.DP.Length);
fs.Write(param.DQ, 0, param.DQ.Length);
fs.Write(param.InverseQ, 0, param.InverseQ.Length);
fs.Write(param.Exponent, 0, param.Exponent.Length);
fs.Write(param.Modulus, 0, param.Modulus.Length);
fs.Close();
}
------------------------------------------------------
however, something goes wrong with reading the private key:
------------------------------------------------------
private RSAParameters ReadPrivateKeyFromFile(string fileName)
{
RSAParameters param = new RSAParameters();

FileStream fs = File.OpenRead(fileName);
fs.Read(param.P, 0, param.P.Length); //large prime
fs.Read(param.Q, 0, param.Q.Length); //large prime
fs.Read(param.D, 0, param.D.Length); //private exponent
fs.Read(param.DP, 0, param.DP.Length);
fs.Read(param.DQ, 0, param.DQ.Length);
fs.Read(param.InverseQ, 0, param.InverseQ.Length);
fs.Read(param.Exponent, 0, param.Exponent.Length);
fs.Read(param.Modulus, 0, param.Modulus.Length);
fs.Close();
return param;
}
------------------------------------------------------
the above function was called inside a method named:
------------------------------------------------------
private void RSADecryptFile(String sInputFilename, String sOutputFilename)
{
FileStream fsread = new FileStream(sInputFilename, FileMode.Open, FileAccess.Read);
FileStream fsDecrypted = new FileStream(sOutputFilename, FileMode.Create, FileAccess.Write);

RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

// Read the file text to the byte array.
byte[] bytearrayinput = new byte[fsread.Length];
fsread.Read(bytearrayinput, 0, bytearrayinput.Length);

RSA.ImportParameters(ReadPrivateKeyFromFile(sOutputFilename+".rsa.private"));
RSA.ImportParameters(ReadPublicKeyFromFile(sOutputFilename+".rsa.public"));

byte[] RSAOutput = RSA.Decrypt(bytearrayinput, false);
// Write out the DES encrypted file.
fsDecrypted.Write(RSAOutput, 0, RSAOutput.Length);

fsDecrypted.Close();
fsread.Close();
}
------------------------------------------------------
i obtain the error state that "Object reference not set to an instance of an object" which occur at line fs.Read(param.P, 0, param.P.Length) in method ReadPrivateKeyFromFile.

i was wondering whether u can give me any suggestion how can i solve this problem?

thank you.

regards
yccheok
Generalreading a minimized form/window into a bitmap?how do i read a minimized form/window into a bitmap. Pin
peenu30-Jun-03 20:42
peenu30-Jun-03 20:42 
QuestionHow to upload a web-application? Pin
puppiesLover30-Jun-03 20:22
puppiesLover30-Jun-03 20:22 
QuestionConstrain form to horizontal resize only? Pin
james-cxx30-Jun-03 19:27
james-cxx30-Jun-03 19:27 
AnswerRe: Constrain form to horizontal resize only? Pin
Jim Stewart30-Jun-03 19:59
Jim Stewart30-Jun-03 19:59 
AnswerRe: Constrain form to horizontal resize only? Pin
peenu30-Jun-03 21:46
peenu30-Jun-03 21:46 
GeneralRe: Constrain form to horizontal resize only? Pin
james-cxx1-Jul-03 5:12
james-cxx1-Jul-03 5:12 
GeneralGDI Tip of the Day Pin
leppie30-Jun-03 18:14
leppie30-Jun-03 18:14 
GeneralRe: GDI Tip of the Day Pin
Oleksandr Kucherenko30-Jun-03 21:44
Oleksandr Kucherenko30-Jun-03 21:44 
GeneralRe: GDI Tip of the Day Pin
Nathan Blomquist1-Jul-03 2:12
Nathan Blomquist1-Jul-03 2:12 
GeneralRe: GDI Tip of the Day Pin
Oleksandr Kucherenko1-Jul-03 2:21
Oleksandr Kucherenko1-Jul-03 2:21 
GeneralRe: GDI Tip of the Day Pin
Nathan Blomquist1-Jul-03 2:39
Nathan Blomquist1-Jul-03 2:39 
GeneralRe: GDI Tip of the Day Pin
leppie1-Jul-03 7:02
leppie1-Jul-03 7:02 
GeneralRe: GDI Tip of the Day Pin
leppie1-Jul-03 6:59
leppie1-Jul-03 6:59 
GeneralRe: GDI Tip of the Day Pin
Nathan Blomquist1-Jul-03 2:14
Nathan Blomquist1-Jul-03 2:14 
GeneralRe: GDI Tip of the Day Pin
leppie1-Jul-03 7:04
leppie1-Jul-03 7:04 
Generalabout WebBrowser in mdi Pin
benzite30-Jun-03 15:02
benzite30-Jun-03 15:02 
GeneralListView Column Width Pin
.gonad30-Jun-03 14:33
.gonad30-Jun-03 14:33 

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.