SEPA: hash totaal berekenen van exportbestand

Maximus
Member Posts: 105
Hoi,
ik wilde mijn oplossing delen om een hash totaal te kunnen berekenen van een SEPA export bestand mbv de MD5 en SHA-1 methode. De software van onze bank biedt de mogelijkheid om deze te berekenen als het SEPA bestand bij hun geupload wordt. Door het aan de Navision kant ook te berekenen kunnen we controleren of het bestand tussentijds aangepast is.
Allereerst heb je het programma fciv.exe nodig van MS: http://support2.microsoft.com/kb/841290. Dit programma berekend hashtotalen en geeft deze terug in een xml bestand. Dit bestand kun je vervolgens uitlezen.
Plaats fciv.exe op een voor iedereen toeganglijke plek op het bedrijfsnetwerk.
Voeg de volgende velden toe in Table 11000001 Payment History:
Enabled Field No. Field Name Data Type Length Description
Yes 50000 Hash Total MD5 Text 32
Yes 50010 Hash Total SHA-1 Text 40
Yes 50020 Hash Total Calculated Boolean
Alle velden staan op Editable is No
Voeg deze velden desgewenst toe op Forms 11000005 Payment History Card en/of 11000007 Payment History List.
Voeg in Table 11000001 Payment History de volgende regel code toe in functie GenerateExportfilename:
Export:=FALSE;
"Hash Total Calculated" := FALSE; //Nieuwe regel code
MODIFY;
Maak in Table 11000001 Payment History een nieuwe functie aan: CalculateHashTotals
CalculateHashTotals()
IF NOT "Hash Total Calculated" THEN BEGIN
"Hash Total MD5" := LCduHashManagement.CalcMD5(Rec);
"Hash Total SHA-1" := LCduHashManagement.CalcSHA1(Rec);
"Hash Total Calculated" := TRUE;
MODIFY;
END;
Deze functie heeft de volgende locale variabele:
Name DataType Subtype Length
LCduHashManagement Codeunit Hash Management
Roep deze functie vervolgens aan in Report 11000012 SEPA ISO20022 Pain 01.01.03:
Payment History - OnAfterGetRecord()
ExportFileName := GenerateExportfilename(AlwaysNewFileName);
ExportSEPAFile;
"Payment History".CalculateHashTotals; //Nieuwe regel code
Tenslotte heb je nog een CodeUnit Hash Management nodig met de volgende Variables, Text Constant en Functions:
Variables
Name DataType Subtype Length
FileNameHashTotals Text 1024
FileHashTotals File
FileHashTotalsTextLine Text 1024
MD5 Text 32
SHA1 Text 40
Text Constant
Name ConstValue
FCIVExecutable Pad en bestandsnaam van fciv.exe
Function Names
CalcMD5
CalcSHA1
CalcMD5(ParRecPaymentHistory : Record "Payment History") : Text[32]
SHELL(FCIVExecutable, ParRecPaymentHistory."File on Disk", '-md5', Parameter 3);
//FCIVExecutable = Text Constant (to make the Executable trusted) containing the Path and File Name of FCIV.exe
//Parameter 1 = Path and File Name of File to calculate Hash Total of
//Parameter 2 = Hash Method used (can be -md5, -sha1 or -both)
//Parameter 3 = Indication that the output has to be a XML File in a location specified ('-xml ' + Path and File Name)
SLEEP(2000); //System needs time to finish FCIV.exe before the resulting XML File can be used
FileHashTotals.OPEN(Path and File Name XML File);
FileHashTotals.READ(FileHashTotalsTextLine);
FileHashTotals.CLOSE;
ERASE(Path and File Name XML File);
MD5 := COPYSTR(FileHashTotalsTextLine,
STRPOS(FileHashTotalsTextLine,'<MD5>') + strlen('<MD5>'),
STRPOS(FileHashTotalsTextLine,'</MD5>') - STRPOS(FileHashTotalsTextLine,'<MD5>') - strlen('<MD5>'));
EXIT(MD5);
CalcSHA1(ParRecPaymentHistory : Record "Payment History") : Text[40]
SHELL(FCIVExecutable, ParRecPaymentHistory."File on Disk", '-sha1', Parameter 3);
//FCIVExecutable = Text Constant (to make the Executable trusted) containing the Path and File Name of FCIV.exe
//Parameter 1 = Path and File Name of File to calculate Hash Total of
//Parameter 2 = Hash Method used (can be -md5, -sha1 or -both)
//Parameter 3 = Indication that the output has to be a XML File in a location specified ('-xml ' + Path and File Name)
SLEEP(2000); //System needs time to finish FCIV.exe before the resulting XML File can be used
FileHashTotals.OPEN(Path and File Name XML File);
FileHashTotals.READ(FileHashTotalsTextLine);
FileHashTotals.CLOSE;
ERASE(Path and File Name XML File);
SHA1 := COPYSTR(FileHashTotalsTextLine,
STRPOS(FileHashTotalsTextLine,'<SHA1>') + strlen('<SHA1>'),
STRPOS(FileHashTotalsTextLine,'</SHA1>') - STRPOS(FileHashTotalsTextLine,'<SHA1>') - strlen('<SHA1>'));
EXIT(SHA1);
Succes ermee.
Gr. Max
ik wilde mijn oplossing delen om een hash totaal te kunnen berekenen van een SEPA export bestand mbv de MD5 en SHA-1 methode. De software van onze bank biedt de mogelijkheid om deze te berekenen als het SEPA bestand bij hun geupload wordt. Door het aan de Navision kant ook te berekenen kunnen we controleren of het bestand tussentijds aangepast is.
Allereerst heb je het programma fciv.exe nodig van MS: http://support2.microsoft.com/kb/841290. Dit programma berekend hashtotalen en geeft deze terug in een xml bestand. Dit bestand kun je vervolgens uitlezen.
Plaats fciv.exe op een voor iedereen toeganglijke plek op het bedrijfsnetwerk.
Voeg de volgende velden toe in Table 11000001 Payment History:
Enabled Field No. Field Name Data Type Length Description
Yes 50000 Hash Total MD5 Text 32
Yes 50010 Hash Total SHA-1 Text 40
Yes 50020 Hash Total Calculated Boolean
Alle velden staan op Editable is No
Voeg deze velden desgewenst toe op Forms 11000005 Payment History Card en/of 11000007 Payment History List.
Voeg in Table 11000001 Payment History de volgende regel code toe in functie GenerateExportfilename:
Export:=FALSE;
"Hash Total Calculated" := FALSE; //Nieuwe regel code
MODIFY;
Maak in Table 11000001 Payment History een nieuwe functie aan: CalculateHashTotals
CalculateHashTotals()
IF NOT "Hash Total Calculated" THEN BEGIN
"Hash Total MD5" := LCduHashManagement.CalcMD5(Rec);
"Hash Total SHA-1" := LCduHashManagement.CalcSHA1(Rec);
"Hash Total Calculated" := TRUE;
MODIFY;
END;
Deze functie heeft de volgende locale variabele:
Name DataType Subtype Length
LCduHashManagement Codeunit Hash Management
Roep deze functie vervolgens aan in Report 11000012 SEPA ISO20022 Pain 01.01.03:
Payment History - OnAfterGetRecord()
ExportFileName := GenerateExportfilename(AlwaysNewFileName);
ExportSEPAFile;
"Payment History".CalculateHashTotals; //Nieuwe regel code
Tenslotte heb je nog een CodeUnit Hash Management nodig met de volgende Variables, Text Constant en Functions:
Variables
Name DataType Subtype Length
FileNameHashTotals Text 1024
FileHashTotals File
FileHashTotalsTextLine Text 1024
MD5 Text 32
SHA1 Text 40
Text Constant
Name ConstValue
FCIVExecutable Pad en bestandsnaam van fciv.exe
Function Names
CalcMD5
CalcSHA1
CalcMD5(ParRecPaymentHistory : Record "Payment History") : Text[32]
SHELL(FCIVExecutable, ParRecPaymentHistory."File on Disk", '-md5', Parameter 3);
//FCIVExecutable = Text Constant (to make the Executable trusted) containing the Path and File Name of FCIV.exe
//Parameter 1 = Path and File Name of File to calculate Hash Total of
//Parameter 2 = Hash Method used (can be -md5, -sha1 or -both)
//Parameter 3 = Indication that the output has to be a XML File in a location specified ('-xml ' + Path and File Name)
SLEEP(2000); //System needs time to finish FCIV.exe before the resulting XML File can be used
FileHashTotals.OPEN(Path and File Name XML File);
FileHashTotals.READ(FileHashTotalsTextLine);
FileHashTotals.CLOSE;
ERASE(Path and File Name XML File);
MD5 := COPYSTR(FileHashTotalsTextLine,
STRPOS(FileHashTotalsTextLine,'<MD5>') + strlen('<MD5>'),
STRPOS(FileHashTotalsTextLine,'</MD5>') - STRPOS(FileHashTotalsTextLine,'<MD5>') - strlen('<MD5>'));
EXIT(MD5);
CalcSHA1(ParRecPaymentHistory : Record "Payment History") : Text[40]
SHELL(FCIVExecutable, ParRecPaymentHistory."File on Disk", '-sha1', Parameter 3);
//FCIVExecutable = Text Constant (to make the Executable trusted) containing the Path and File Name of FCIV.exe
//Parameter 1 = Path and File Name of File to calculate Hash Total of
//Parameter 2 = Hash Method used (can be -md5, -sha1 or -both)
//Parameter 3 = Indication that the output has to be a XML File in a location specified ('-xml ' + Path and File Name)
SLEEP(2000); //System needs time to finish FCIV.exe before the resulting XML File can be used
FileHashTotals.OPEN(Path and File Name XML File);
FileHashTotals.READ(FileHashTotalsTextLine);
FileHashTotals.CLOSE;
ERASE(Path and File Name XML File);
SHA1 := COPYSTR(FileHashTotalsTextLine,
STRPOS(FileHashTotalsTextLine,'<SHA1>') + strlen('<SHA1>'),
STRPOS(FileHashTotalsTextLine,'</SHA1>') - STRPOS(FileHashTotalsTextLine,'<SHA1>') - strlen('<SHA1>'));
EXIT(SHA1);
Succes ermee.
Gr. Max
0
Comments
-
Dank voor het delen Max!
=D>
Tino Ruijs
Microsoft Dynamics NAV specialist0 -
I just browsed your code, but shouldn't SHA1 be a text40? MD5 is 32 characters, but SHA1 is 40 characters
Oeps, nederlands. SHA1 is toch altijd 40 karakters?0 -
Hoi Poltergeist,
je hebt gelijk :oops: het moet 40 zijn.
Ik heb mijn originele post aangepast om verwarring en onnodige fouten te voorkomen.
Niemand die het hier gemerkt heeft overigens
Een andere issue waar ik tegenaan liep: fciv.exe berekent hash totalen in hexadecimaal formaat maar converteert dit naar Base64 voor het naar het scherm of de XML-outputfile gestuurd wordt.
Grappige is dat de website van de bank de hashtotalen alleen in hexadecimaal formaat toont. Onze collega's van Finance halen nu het hashtotaal dat door NAV berekend wordt door een offline converter zodat ze een verglijking kunnen maken. Het mooiste is natuurlijk als het goede formaat al in NAV getoond wordt. Iemand toevallig een converteerfucntie Base64 -> Hex beschikbaar?
Gr. Max0 -
Dat komt omdat je de -xml optie gebruikt. Wat je beter kunt doen is dit regeltje gebruiken
fciv bestandsnaam -both > outputfile.txt
In outputfile.txt komt op de laatste regel dan de md5 en de sha1 in hex en de bestandsnaam te staan. Die kun je gewoon uitlezen0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions