Click here to Skip to main content
15,888,984 members
Home / Discussions / C#
   

C#

 
GeneralRe: Crystal report Pin
Sun Rays6-May-09 0:28
Sun Rays6-May-09 0:28 
Questioncmd.exe standardinput problem, please help?!?! Pin
Druuler5-May-09 23:41
Druuler5-May-09 23:41 
AnswerRe: cmd.exe standardinput problem, please help?!?! Pin
12Code6-May-09 0:25
12Code6-May-09 0:25 
GeneralRe: cmd.exe standardinput problem, please help?!?! Pin
Druuler6-May-09 0:31
Druuler6-May-09 0:31 
GeneralRe: cmd.exe standardinput problem, please help?!?! Pin
12Code6-May-09 0:45
12Code6-May-09 0:45 
GeneralRe: cmd.exe standardinput problem, please help?!?! Pin
Druuler6-May-09 1:18
Druuler6-May-09 1:18 
QuestionExtended Ascii charaters are not written in the text file.... Pin
King Julien5-May-09 23:37
King Julien5-May-09 23:37 
AnswerRe: Extended Ascii charaters are not written in the text file.... Pin
OriginalGriff5-May-09 23:50
mveOriginalGriff5-May-09 23:50 
Converting from a byte[] to a char[] is odd, because the two values are not the same at all.
The bytes you (correctly I think) have in your encrypted data are unsigned 8 bit quantities. Chars are 16 bit unicode quantities. Since you are then trying to write these to an ASCII encoded (7 or 8 bit depending on who you talk to) there is some oddness here.

Why not just write the byte[] to a normal filestream? Or encrypt it into the filestream directly? There is a cryptostream, after all...

Here is my generic encrypt routine (uses RSATriple)

public void Encrypt(Stream sIn, Stream sOut)
    {
    /*
     * Notes:
     * We do NOT close sIn or sOut.
     * Since these could be MemoryStreams, closing them
     * would throw away the data!
     * It is good practice to decrypt to memory, not file!
     *
     * We don't work with files bigger than an int full.
     * It would be fairly easy to modify this to block the I/O
     *
     * We make the output bigger than it needs to be to flush
     * all the "real" data to the output.
     * (This should not be necessary, but when decrypting to a
     * MemoryStream you have to close it to get the last block.
     * Don't ask me why - ask MS.)
     */
    string Routine = "Encrypt: ";
    if (key == null)
        {
        throw new Exception(Routine + EX_CRYPTO_NOKEY);
        }
    if (sIn.Length > int.MaxValue)
        {
        throw new Exception(Routine + EX_CRYPTO_TOOBIG);
        }
    sOut.Write(CreateBlockHeader(sIn), 0, encAlg.BlockSize);
    CryptoStream encrypt = new CryptoStream(sOut, encAlg.CreateEncryptor(), CryptoStreamMode.Write);
    int inputLength = (int)sIn.Length + encAlg.BlockSize; // Make it too big!
    byte[] abIn = new byte[inputLength];
    sIn.Read(abIn, 0, inputLength);
    encrypt.Write(abIn, 0, inputLength);
    encrypt.FlushFinalBlock();
    key.Reset();
    if (sIn.CanSeek)
        {
        sIn.Seek(0, SeekOrigin.Begin);
        }
    if (sOut.CanSeek)
        {
        sOut.Seek(0, SeekOrigin.Begin);
        }
    }


[EDIT]Edited to correct spelling errors caused by dyslexic keyboard[/EDIT]

No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.

This message is made of fully recyclable Zeros and Ones

GeneralRe: Extended Ascii charaters are not written in the text file.... Pin
King Julien6-May-09 0:22
King Julien6-May-09 0:22 
GeneralRe: Extended Ascii charaters are not written in the text file.... Pin
OriginalGriff6-May-09 0:41
mveOriginalGriff6-May-09 0:41 
AnswerRe: Extended Ascii charaters are not written in the text file.... Pin
Guffa6-May-09 4:18
Guffa6-May-09 4:18 
GeneralRe: Extended Ascii charaters are not written in the text file.... Pin
King Julien6-May-09 4:37
King Julien6-May-09 4:37 
QuestionMouseDown Event? [modified] Pin
Megidolaon5-May-09 23:25
Megidolaon5-May-09 23:25 
AnswerRe: MouseDown Event? Pin
Alex@UEA5-May-09 23:40
Alex@UEA5-May-09 23:40 
AnswerRe: MouseDown Event? Pin
OriginalGriff6-May-09 0:00
mveOriginalGriff6-May-09 0:00 
GeneralRe: MouseDown Event? Pin
Megidolaon7-May-09 20:51
Megidolaon7-May-09 20:51 
GeneralRe: MouseDown Event? Pin
OriginalGriff7-May-09 21:58
mveOriginalGriff7-May-09 21:58 
AnswerRe: MouseDown Event? Pin
Member 3046636-May-09 6:54
Member 3046636-May-09 6:54 
QuestionExporting excel to pdf Pin
tauras815-May-09 23:15
tauras815-May-09 23:15 
AnswerRe: Exporting excel to pdf Pin
Mycroft Holmes5-May-09 23:26
professionalMycroft Holmes5-May-09 23:26 
GeneralRe: Exporting excel to pdf Pin
tauras816-May-09 0:14
tauras816-May-09 0:14 
QuestionInvalid attempt to call MetaData when reader is closed. Pin
Vimalsoft(Pty) Ltd5-May-09 23:10
professionalVimalsoft(Pty) Ltd5-May-09 23:10 
AnswerRe: Invalid attempt to call MetaData when reader is closed. Pin
Mycroft Holmes5-May-09 23:24
professionalMycroft Holmes5-May-09 23:24 
GeneralRe: Invalid attempt to call MetaData when reader is closed. Pin
Vimalsoft(Pty) Ltd5-May-09 23:37
professionalVimalsoft(Pty) Ltd5-May-09 23:37 
GeneralRe: Invalid attempt to call MetaData when reader is closed. Pin
Mycroft Holmes6-May-09 14:16
professionalMycroft Holmes6-May-09 14:16 

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.