Rob,
I finally got it this morning...here's what I was trying to do
exactly: The C# code was as follows:
///////////////////// START CODE
//////////////////////////////////////////////////
[C#]
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
namespace RijndaelManaged_Examples
{
class MyMainClass
{
public static void Main()
{
string original = "This is a much longer string of data than a
public/private key algorithm will accept.";
string roundtrip;
ASCIIEncoding textConverter = new ASCIIEncoding();
RijndaelManaged myRijndael = new RijndaelManaged();
byte[] fromEncrypt;
byte[] encrypted;
byte[] toEncrypt;
byte[] key;
byte[] IV;
//Create a new key and initialization vector.
myRijndael.GenerateKey();
myRijndael.GenerateIV();
//Get the key and IV.
key = myRijndael.Key;
IV = myRijndael.IV;
//Get an encryptor.
ICryptoTransform encryptor = myRijndael.CreateEncryptor(key,
IV);
//Encrypt the data.
MemoryStream msEncrypt = new MemoryStream();
CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor,
CryptoStreamMode.Write);
//Convert the data to a byte array.
toEncrypt = textConverter.GetBytes(original);
//Write all data to the crypto stream and flush it.
csEncrypt.Write(toEncrypt, 0, toEncrypt.Length);
csEncrypt.FlushFinalBlock();
//Get encrypted array of bytes.
encrypted = msEncrypt.ToArray();
/////////////////////////// END CODE ///////////////////////////////
And here is what I finally did to convert it to a class method that could be
used in NET:
////////////////// START CODE /////////////////////////////////////
class Method MyEncryptHandlers.EncryptData(OriginalStr : String): String;
begin
Var Keyb : Array of Byte;
Var IVb : Array of Byte;
Var MyRijndael : RijndaelManaged;
myRijndael.GenerateKey;
myRijndael.GenerateIV;
Keyb := myRijndael.Key;
IVb := myRijndael.IV;
Var textConverter : ASCIIEncoding := new ASCIIEncoding;
Var msEncrypt : MemoryStream := New MemoryStream;
Var encryptor : ICryptoTransform := myRijndael.CreateEncryptor(Keyb,
IVb);
Var csEncrypt : CryptoStream := New CryptoStream(msEncrypt,
encryptor, CryptoStreamMode.Write);
Var toEncrypt : Array of Byte :=
textConverter.GetBytes(OriginalStr);
csEncrypt.Write(toEncrypt, 0, toEncrypt.Length);
csEncrypt.FlushFinalBlock;
Result := textconverter.GetString(toEncrypt);
end;
////////////////// END CODE ////////////////////////////////////
As you can see it was basically a metter of using byte arrays.
Also, I had had trouble with the textconverter because I wasn't using arrays
to begin with so I didn't need to use TextEncoding at all. Once you get the
hang of it it's not to bad, but when I'm so used to just dropping components
on a form and calling functions it takes a little getting used to! Nice
thing about NET though is that a lot of what one had to go to outside
libraries for is already included in the clr!
Thing is, I wonder if this isn't overkill for small strings?
from: Robert Meek at: [EMAIL PROTECTED]
dba "Tangentals Design" home of "PoBoy"
freeware Windows apps and utilities
located at: www.TangentalsDesign.com
Proud to be a moderator for the
"Delphi Programming Lists" at: elists.org
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi