NET API
HSM Dinamo
Loading...
Looking for...
No entries found
spb_file_cip.cs

Example of using the SPB API (Brazilian Payment System) using files.

See Note on examples.
using System;
using System.IO;
using Dinamo.Hsm;
namespace SPBEncodeDecodeCIPFile
{
class Program
{
static void Main(string[] args)
{
string address = "10.0.0.1";
string user = "usuario";
string pass = "12345678";
//Conecta ao HSM
din.Connect(address, user, pass);
string srcISPB = "12345678";
string dstISPB = "12345678";
try
{
//Nome do arquivo original.
string clearTextFileName = @"c:\tmp\teste.txt";
//Nome do arquivo que conterĂ¡ o arquivo original codificado.
string encodedFileName = @"c:\tmp\test_encoded.txt";
//Nome do arquivo que conterĂ¡ a mensagem decodificada.
string decodedFileName = @"c:\tmp\teste_decoded.txt";
/*
* Encode the file.
*/
FileStream clearTextFile = File.OpenRead(clearTextFileName);
FileStream outEncodedFile = File.OpenWrite(encodedFileName);
din.SPBEncode( srcISPB,
dstISPB,
clearTextFile,
outEncodedFile,
0x00,
0x00,
outEncodedFile.Close();
clearTextFile.Close();
Console.WriteLine("File encoded successfully.");
/*
* Decodes the file generated by the encode operation.
*/
FileStream inEncodedFile = File.OpenRead(encodedFileName);
FileStream outDecodedFile = File.OpenWrite(decodedFileName);
din.SPBDecode( dstISPB,
srcISPB,
inEncodedFile,
outDecodedFile,
false,
false,
inEncodedFile.Close();
outDecodedFile.Close();
Console.WriteLine("File decoded successfully.");
}
catch (DinamoException e)
{
Console.WriteLine(e.ErrorCode);
Console.WriteLine(e.Message);
}
finally
{
din.Disconnect();
}
}
}
}
Low-level class for accessing the HSM. To use this class you need to understand more ...
Definition DinamoApi.cs:15
const UInt32 ND_SPB_USE_CIP1
Definition DinamoApi.cs:1297
const UInt32 ND_SPB_USE_ANY
Definition DinamoApi.cs:1298
const UInt32 ND_SPB_OUT_NO_PADDING
Definition DinamoApi.cs:1310
API class for accessing HSM functionalities Dinamo. In this class you can program using...
Definition DinamoClient.cs:93
Exception class for errors from Dinamo.
Definition DinamoException.cs:10
override string Message
Definition DinamoException.cs:42
int ErrorCode
Definition DinamoException.cs:26
void Connect(string User, string Password)
Establishes an encrypted connection to the HSM using the load balance settings.
Definition DinamoClient.cs:562
void Disconnect(bool flagClose)
Terminates the connection to the HSM.
Definition DinamoClient.cs:814
byte[] SPBEncode(string szSrcISPB, string szDstISPB, byte[] pbMsgIn, byte bSpecialTreatment)
It encodes a message with the SPB header, signing, encrypting and including all the fields...
Definition DinamoClient.cs:6375
byte[] SPBDecode(string szSrcISPB, string szDstISPB, byte[] pbMsgIn)
Decrypts a message in the SPB standard, checking the signatures, decrypting it, but does not check...
Definition DinamoClient.cs:6535
Namespace denoting a set of functions for accessing the HSM Dinamo and their respective exceptions.
Definition DinamoClient.cs:12