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

C#

 
Questionhow to access c# array in VBA Pin
newbieNeeraj26-Sep-08 20:02
newbieNeeraj26-Sep-08 20:02 
AnswerRe: how to access c# array in VBA Pin
Pedram Behroozi26-Sep-08 20:58
Pedram Behroozi26-Sep-08 20:58 
GeneralRe: how to access c# array in VBA Pin
newbieNeeraj26-Sep-08 21:17
newbieNeeraj26-Sep-08 21:17 
GeneralRe: how to access c# array in VBA [modified] Pin
Pedram Behroozi26-Sep-08 21:43
Pedram Behroozi26-Sep-08 21:43 
GeneralRe: how to access c# array in VBA Pin
newbieNeeraj28-Sep-08 14:31
newbieNeeraj28-Sep-08 14:31 
GeneralRe: how to access c# array in VBA Pin
Pedram Behroozi1-Oct-08 3:08
Pedram Behroozi1-Oct-08 3:08 
QuestionHow to work with Method : Find in richTextBox Pin
Laji5926-Sep-08 19:49
Laji5926-Sep-08 19:49 
AnswerRe: How to work with Method : Find in richTextBox Pin
Pedram Behroozi26-Sep-08 21:09
Pedram Behroozi26-Sep-08 21:09 
GeneralRe: How to work with Method : Find in richTextBox Pin
Laji5926-Sep-08 21:17
Laji5926-Sep-08 21:17 
GeneralRe: How to work with Method : Find in richTextBox Pin
Pedram Behroozi26-Sep-08 21:32
Pedram Behroozi26-Sep-08 21:32 
Questionhow we implement Slide-In Menu Bar in windows application using c#? Pin
g_amol26-Sep-08 19:22
g_amol26-Sep-08 19:22 
AnswerRe: how we implement Slide-In Menu Bar in windows application using c#? Pin
Pedram Behroozi26-Sep-08 19:47
Pedram Behroozi26-Sep-08 19:47 
GeneralRe: how we implement Slide-In Menu Bar in windows application using c#? Pin
g_amol26-Sep-08 19:55
g_amol26-Sep-08 19:55 
GeneralRe: how we implement Slide-In Menu Bar in windows application using c#? Pin
Pedram Behroozi26-Sep-08 20:43
Pedram Behroozi26-Sep-08 20:43 
AnswerRe: how we implement Slide-In Menu Bar in windows application using c#? Pin
Noble KC14-Nov-14 17:32
professionalNoble KC14-Nov-14 17:32 
Questionthere is no server Pin
reza assar26-Sep-08 13:22
reza assar26-Sep-08 13:22 
Jokethere is no spoon Pin
Nicholas Butler27-Sep-08 0:00
sitebuilderNicholas Butler27-Sep-08 0:00 
Questionimplementing wildcard match method Pin
AndrusM26-Sep-08 12:15
AndrusM26-Sep-08 12:15 
AnswerRe: implementing wildcard match method Pin
Anthony Mushrow26-Sep-08 12:29
professionalAnthony Mushrow26-Sep-08 12:29 
AnswerRe: implementing wildcard match method Pin
Paul Conrad27-Sep-08 5:05
professionalPaul Conrad27-Sep-08 5:05 
GeneralRe: implementing wildcard match method Pin
AndrusM28-Sep-08 22:44
AndrusM28-Sep-08 22:44 
QuestionSystem.Security.Cryptography for encrypting binary files (not plain text) Pin
Cyrilix26-Sep-08 9:01
Cyrilix26-Sep-08 9:01 
Is there a way to use the .NET cryptography library to encrypt binary files as opposed to plain text files? I've been having a few issues with the way that encrypted bytes are decrypted back to their original state.

What I do to initialize my algorithm for decryption is approximately the following:
UnicodeEncoding byteConverter = new UnicodeEncoding();
RijndaelManaged algorithm = new RijndaelManaged();
algorithm.IV = byteConverter->GetBytes(/*a unicode string converted to bytes for init vector*/);
algorithm.Key = byteConverter->GetBytes(/*a unicode string converted to bytes for password*/);
return alg; //returned as base class "SymmetricAlgorithm"

In order to encrypt, first, I call that stub of algorithm initialization code. Then I do approximately the following with a Byte[] data that I want to encrypt:
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, algorithm.CreateEncryptor(), CryptoStreamMode.Write);
for (int i = 0; i < numBytes; i++)
{
  cs.WriteByte(data[i]);
}
cs.FlushFinalBlock();
byte encoded[] = ms.ToArray();
cs.Close();
ms.Close();
string output = Convert.ToBase64String(encoded);

In order to decrypt, first, I call that stub of algorithm initialization code. Then I do approximately the following with a string input that I want to decrypt:
byte[] encoded = Convert.FromBase64String(input);
MemoryStream ms = new MemoryStream(encoded);
CryptoStream cs = new CryptoStream(ms, algorithm.CreateDecryptor(), CryptoStreamMode.Read);
byte decoded[] = new byte[encoded.Length];
for (int i = 0; i < decoded.Length; i++)
{
  int readByte = cs.ReadByte();
  if (readByte != -1)
  {
    decoded[i] = (byte)readByte;
  }
}
cs.Close();
ms.Close();

The problem is that if I call Encrypt, then Decrypt, encryption leaves me with a nice base64 string, which decrypt easily converts back to a byte array. But when I read the CryptoStream and get check all the values of int readByte everytime I read a byte, as soon as I come to the null-terminated character (0 ''), everything else that I read after that is the same garbage symbol (-51 'Í'). More precisely, the code that I'm writing here is the C# equivalent of my Managed C++ code (however, the problem does not lie in the unmanaged part or the unmanaged/managed conversion). So, to rephrase what I mean, say that I'm checking all the values of readByte for i = 0 to the length of the decoded byte array (which hasn't yet been filled), if ReadByte happens to return me 66, 77, 54, 44, 23, 0, respectively, everything else after that is -51. If I'm decrypting binary data, I will run into this issue. If I'm decrypting text data, then I won't, since in a text string, 0 is the null-terminated character that only occurs at the very end of the string (and I've got all my bytes at that point anyway).

Any suggestions? Thanks, and I apologize for the long post.
AnswerRe: System.Security.Cryptography for encrypting binary files (not plain text) Pin
Ennis Ray Lynch, Jr.26-Sep-08 10:06
Ennis Ray Lynch, Jr.26-Sep-08 10:06 
GeneralRe: System.Security.Cryptography for encrypting binary files (not plain text) Pin
Cyrilix26-Sep-08 10:42
Cyrilix26-Sep-08 10:42 
GeneralRe: System.Security.Cryptography for encrypting binary files (not plain text) Pin
Cyrilix26-Sep-08 12:44
Cyrilix26-Sep-08 12:44 

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.