Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with C# to VFP translation
Message
From
21/06/2010 16:13:34
 
General information
Forum:
Visual FoxPro
Category:
Contracts, agreements and general business
Miscellaneous
Thread ID:
01469828
Message ID:
01470019
Views:
111
Sorry but my VFP is getting rustier by the day but, as stated, it should be simply a matter of a few judicious STRTOFILE() and FILETOSTR() lines. Don't know which bit you can't do but (top of my head) the encrypt would be something like:
TempPath = "C:\Test.req"
StringToEncrypt = "SomeThing"
STRTOFILE("",TempPath)
xx = CREATEOBJECT("EncryptionManager")
s = xx.EncrptThirdPartyMessage(TempPath,StringToEncrypt)
STRTOFILE(s,TempPath)
* Then copy to output folder
Decrypt pretty much the same principle but maybe using ALINES() and processing each line. Someone still active in VFP should be able to straighten me out if that's wrong.......

>Thanks Viv;
>The steps you listed, is what I need the help with.
>
>Cyrus
>
>>Hi,
>>Most of the C# code is just for creating, reading and writing to files. Should be simple in VFP:
>>
>>Encrypting:
>>1. Create a file with the *.req extension in the required folder.
>>2. Create an instance of the EncryptionManager.
>>3. Call its EncryptThirdPartyMessage() method passing in the name of the created file (including the full path) and the string to encrypt
>>4. Write the return value to the file.
>>5. Copy the file to the output location.
>>
>>Decrypting (looks as if the input file can contain multiple strings?):
>>1. Create a file to hold the output.
>>2. Open the input file
>>3. For each line in the input file
>> (a) Call DecryptThirdPartyMessage() passing in the fullname of the input file and the line string
>> (b) Write the returned string to the output file.....
>>
>>AFAICS the only reason for passing the filenames to the EncryptionManager methods is that it uses the
>>file timestamp for something ?
>>All the file stuff can probably be done with STRTOFILE() and FILETOSTR()
>>
>>
>>
>>
>>>Thanks Michael; Here it is:
>>>________________________________________________________________________________________________
>>>TO ENCRYPT THE STRING:
>>>
>>>(Sample code is written in C#.Net)
>>>
>>>// File name format that ICVERIFY understand for request processing
>>>string csFileName = "\\icver001.req";
>>>// Shared directory path where file is being created.
>>>string txtSharedDirPath = "C:\\Shared Directory";
>>>string csSharedDirPath = txtSharedDirPath + csFileName;
>>>/*
>>>// Request directory path where file will be used by
>>>// ICVERIFY for transaction processing.
>>>*/
>>>string txtReqPath = "C:\\Request Directory";
>>>string csReqPreparationPath = txtReqPath + csFileName;
>>>// Object of StreamWriter
>>>StreamWriter objWriter = null;
>>>// This code is creating an empty file in shared directory path
>>>FileStream objFileStream = new FileStream(csSharedDirPath, FileMode.Create, FileAccess.Write);
>>>objWriter = new StreamWriter(objFileStream);
>>>/*
>>>// To call EncryptionManager.dll to encrypt string
>>>// EncryptionManager.dll will use the creation date of the
>>>// file that was being created in shared directory path.
>>>*/
>>>string csStringToEncrypt = "Some string";
>>>EncryptionManager objEncryptionManager = new EncryptionManager();
>>>string csEncryptedString = objEncryptionManager.EncryptThirdPartyMessage(csSharedDirPath, csStringToEncrypt);
>>>// To write the encrypted string in the file
>>>objWriter.WriteLine(csEncryptedString);
>>>if (objWriter != null)
>>> objWriter.Close();
>>>/*
>>>// Once all the encrypt strings have been written in file,
>>>// move that file into the request directory for processing.
>>>*/
>>>File.Move(csSharedDirPath, csReqPreparationPath);
>>>________________________________________________________________________________________________
>>>
>>>TO DECRYPT THE STRING:
>>>
>>>(Sample code is written in C#.Net)
>>>// File name that need to be decrypted
>>>string csFileName = "\\icver001.ans";
>>>// Shared directory path where decrypted file will be created.
>>>string txtSharedDirPath = "C:\\Shared Directory";
>>>string csSharedDirPath = txtSharedDirPath + csFileName;
>>> /*
>>>// Request directory path where file that needs to be
>>>// decrypted is present.
>>>*/
>>>string txtReqPath = "C:\\Request Directory";
>>>string csReqPreparationPath = txtReqPath+ csFileName;
>>>// object of StreamWriter
>>>StreamWriter objWriter = null;
>>>// This code is creating an empty file in shared directory path
>>>FileStream objFileWriteStream = new FileStream(csSharedDirPath, FileMode.Create, FileAccess.Write);
>>>objWriter = new StreamWriter(objFileWriteStream);
>>>StreamReader objReader = null;
>>>FileStream objFileReadStream = new FileStream(csReqPreparationPath, FileMode.Open, FileAccess.Read);
>>>objReader = new StreamReader(objFileReadStream);
>>>/*
>>>// To call EncryptionManager.dll to decrypt string
>>>// EncryptionManager.dll will use the creation date of the
>>>// file that was being created in Request directory path.
>>> */
>>>EncryptionManager objEncryptionManager = new EncryptionManager();
>>>string strDecString = "";
>>>string strEncString = "";
>>>while (((strEncString = objReader.ReadLine()) != null))
>>>{
>>>strDecString = objEncryptionManager.DecryptThirdPartyMessage(csReqPreparationPath, strEncString);
>>>objWriter.WriteLine(strDecString);
>>>}
>>>if (objReader != null)
>>>objReader.Close();
>>>if (objWriter != null)
>>>objWriter.Close();
>>>________________________________________________________________________________________________
>>>
>>>And they had me run the following to register the DLLs in Windows Command Prompt:
>>>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\IcvGacUtil /i C:\ICVERIFY\ICWin403\SecurityService.dll
>>>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm C:\ICVERIFY\ICWin403\SecurityService.dll /tlb
>>>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\IcvGacUtil /i C:\ICVERIFY\ICWin403\EncryptionManager.dll
>>>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm C:\ICVERIFY\ICWin403\EncryptionManager.dll /tlb
>>>________________________________________________________________________________________________
>>>
>>>Pease let me know the cost, so you can just put it on my card.
>>>Thanks
>>>Cyrus
>>>
>>>
>>>>>I am trying to use an External DLL (supplied by a Payment Transaction company ICVerify) to
>>>>>
>>>>>a) convert a String Variable into an encrypted file, and then
>>>>>b) Decrypt the File into a String variable.
>>>>>
>>>>>They don't have a VFP sample code, but they have supplied Sample Code in C#.
>>>>>It is about 5 to 10 commands. I need to have the C# code translated into VFP code and then some help in getting it to run.
>>>>>
>>>>>Please let me know asap.
>>>>
>>>>Could you simply paste the code in here?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform