Class EbicsUtil
Collection of static utility functions.
public static class EbicsUtil
- Inheritance
-
EbicsUtil
- Inherited Members
Fields
DSigNamespaceURI
public const string DSigNamespaceURI = "http://www.w3.org/2000/09/xmldsig#"
Field Value
DSigSHA1URI
public const string DSigSHA1URI = "http://www.w3.org/2000/09/xmldsig#sha1"
Field Value
DSigSHA256URI
public const string DSigSHA256URI = "http://www.w3.org/2001/04/xmlenc#sha256"
Field Value
Properties
ApiVersion
Provides the version of the Subsembly EBICS API
public static Version ApiVersion { get; }
Property Value
LatinEncoding
public static Encoding LatinEncoding { get; }
Property Value
UTF8Encoding
public static Encoding UTF8Encoding { get; }
Property Value
Methods
AppendElement(XmlElement, string, string, string)
Creates and appends a new child XML element.
public static XmlElement AppendElement(XmlElement xmlParent, string sElementTag, string sElementNamespace, string sElementValue)
Parameters
xmlParentXmlElementThe parent XML element where a new child XML element shall be appended to.
sElementTagstringThe local name of the new XML element to be created.
sElementNamespacestringThe namespace name of the namespace that the local name of the XML element is defined in.
sElementValuestringThe string value of the XML element to create. This will become the InnerText of the new XML element. If this is
null, then this method will do nothing (i.e. it will not append a XML element).
Returns
BuildReturnCodeMessage(EbicsReturnCode, EbicsReturnCode)
Builds a nice message from a technical and a business message.
public static string BuildReturnCodeMessage(EbicsReturnCode aTechnicalReturnCode, EbicsReturnCode aBusinessReturnCode)
Parameters
aTechnicalReturnCodeEbicsReturnCodeThe technical return code to present in the message. May be
nullif not present. The return code will only be included in the message if it is not EBICS_OK.aBusinessReturnCodeEbicsReturnCodeThe business return code to present in the message. May be
nullif not present. The return code will only be included in the message if it is not EBICS_OK.
Returns
- string
A nice message string suitable to be presented in a message box. Or
nullif there is nothing to be reported to the user.
Remarks
Builds a nice, human consumable message string from the given return codes. If
both parameters are null, or hold an EBICS_OK return code, then no
message is generated and null is returned instead.
BytesToXml(byte[])
public static XmlDocument BytesToXml(byte[] vb)
Parameters
vbbyte[]
Returns
CheckFingerprint(bool, EbicsPubKeyInfo, string)
public static bool CheckFingerprint(bool fFromCertificate, EbicsPubKeyInfo aPubKey, string sFingerprint)
Parameters
fFromCertificateboolaPubKeyEbicsPubKeyInfosFingerprintstringString of hex digits and optional whitespace. Hex digits may be lower or upper case. If this is an empty string, contained only whitespace, or is
null, thenfalsewill be returned. If it contains any invalid characters, thenfalsewill be returned.
Returns
- bool
If the given
sFingerprintis invalid, or does not match the public key, thenfalseis returned. If the fingerprint matches the public key, thentrueis returned.
Exceptions
- ArgumentNullException
The parameter
aPubKeywasnull.
DataToXml(EbicsDataBuffer)
Loads an XML document from a raw data buffer.
public static XmlDocument DataToXml(EbicsDataBuffer d)
Parameters
Returns
Exceptions
- ArgumentNullException
The given parameter was
null.- XmlException
The raw data buffer does not contain a valid XML document.
EvaluateOrderResult(EbicsOrder)
Evaluates order result and returns message text for it.
public static string EvaluateOrderResult(EbicsOrder aOrder)
Parameters
aOrderEbicsOrderThe order that was executed. Must not be
null.
Returns
- string
If the order failed, then an approrpiate, detailed error message text is returned. If the order succeeded then
nullis returned.
FormatDate(DateTime)
Format the given date in ISO 8601 date representation.
public static string FormatDate(DateTime tDate)
Parameters
tDateDateTime
Returns
- string
If the given date is DateTime.MinValue, then
nullis returned. Otherwise an ISO date string according to the format "yyyy-MM-dd" is returned.
FormatDateTime(DateTime)
Format the given time stamp in EBICS dateTime format.
public static string FormatDateTime(DateTime tTimestamp)
Parameters
tTimestampDateTime
Returns
Remarks
The EBICS dateTime format is specified as "YYYY-MM-DDTHH:MM:SS.sssZ".
FormatFingerprint(EbicsContact, EbicsPubKeyInfo)
Creates a multi-line formatted fingerprint text for the printed Ini-Letter or UI.
public static string FormatFingerprint(EbicsContact aContact, EbicsPubKeyInfo aPubKey)
Parameters
aContactEbicsContactThe EbicsContact for which to create the formatted fingerprint.
aPubKeyEbicsPubKeyInfo
Returns
FormatFingerprint(EbicsContact, EbicsPubKeyInfo, EbicsFingerprintPart)
Creates a nicely formatted fingerprint for the printed Ini-Letter or UI.
public static string FormatFingerprint(EbicsContact aContact, EbicsPubKeyInfo aPubKey, EbicsFingerprintPart nPart)
Parameters
aContactEbicsContactThe EbicsContact for which to create the formatted fingerprint.
aPubKeyEbicsPubKeyInfonPartEbicsFingerprintPart
Returns
FormatHex(byte[], int)
public static string FormatHex(byte[] vb, int nColumns)
Parameters
Returns
FormatHex(byte[], int, int, int)
public static string FormatHex(byte[] vb, int nOffset, int nLength, int nColumns)
Parameters
Returns
FormatXml(XmlDocument)
Creates a nicely formatted string from the XML document.
public static string FormatXml(XmlDocument xmlDocument)
Parameters
xmlDocumentXmlDocumentThe XML document to be formatted. This must not be null.
Returns
GetAllKnownHosts()
Returns an array of all known Host-IDs.
public static string[] GetAllKnownHosts()
Returns
- string[]
GetAttribute(XmlElement, string)
Get an attribute from an XML element. This method does never return an empty
string, but will return null if an attribute is not present.
public static string GetAttribute(XmlElement xmlElement, string sAttributeName)
Parameters
xmlElementXmlElementsAttributeNamestring
Returns
GetElement(XmlElement, string, string, bool)
Gets the InnerText from a XML element.
public static string GetElement(XmlElement xmlParent, string sElementTag, string sElementNamespace = null, bool fMandatory = false)
Parameters
xmlParentXmlElementThe parent XML element that contains the XML element to be retrieved.
sElementTagstringThe local name of the XML element to be retrieved.
sElementNamespacestringThe namespace name of the namespace that the local name of the XML element is defined in.
fMandatorybool
Returns
- string
If the requested XML element exists, then its InnerText is returned. If the requested XML element does not exist, then
nullis returned.
GetKnownHostURL(string)
Looks up the URL for a given Host ID.
public static string GetKnownHostURL(string sHostID)
Parameters
sHostIDstringThe Host ID for which to look up an URL. Must not be
nullor an empty string.
Returns
- string
If the Host ID is known, then the URL of that host is returned. If the Host ID is not known, then
nullis returned.
Remarks
This method is based on a very small hard coded list. Therefore, for most hosts it won't know the URL.
GetOrderTypeDescription(string)
Returns a descriptive text for a given EBICS order type.
public static string GetOrderTypeDescription(string sOrderType)
Parameters
sOrderTypestringThe EBICS order type consists of three upper case letters.
Returns
- string
If the requested order type is known, then a short, descriptive text is returned. If the order type is not known, then a replacement string including the
sOrderTypeis returned.
Exceptions
- ArgumentNullException
The parameter
sOrderTypewasnull.- ArgumentException
The parameter
sOrderTypewas an empty string.
IsAdminOrderType(string)
Returns true if the given order type is a known admistrative order type.
public static bool IsAdminOrderType(string sOrderType)
Parameters
sOrderTypestring
Returns
Exceptions
- ArgumentNullException
The parameter
sOrderTypewasnull.- ArgumentException
The given order type did not consist of exactly three upper case letters in the range from A-Z or digits.
IsBIC(string)
Check whether a string is a syntactically valid BIC.
public static bool IsBIC(string sBIC)
Parameters
sBICstring
Returns
Remarks
This method does not do any semantic validation of the, it only performs some simple syntactical checks.
IsDigits(string)
Checks whether a string solely consists of digits.
public static bool IsDigits(string s)
Parameters
sstringThe string to be checked.
Returns
- bool
If the given string was
null, thenfalseis returned. If the given string was empty, thentrueis returned. If the string contains only digits, thentrueis returned, otherwisefalseis returned.
IsDigitsOrUpperAscii(string)
Checks whether a string solely consists of digits and upper ASCII characters.
public static bool IsDigitsOrUpperAscii(string s)
Parameters
sstringThe string to be checked.
Returns
- bool
If the given string was
null, thenfalseis returned. If the given string was empty, thentrueis returned. If the string contains only upper ASCII characters in the range 'A' through 'Z' or digits in the range '0' through '9', thentrueis returned, otherwisefalseis returned.
IsIBAN(string)
Check whether a string is a syntactically valid IBAN.
public static bool IsIBAN(string sIBAN)
Parameters
sIBANstring
Returns
IsUpperAscii(string)
Checks whether a string solely consists of upper ASCII characters.
public static bool IsUpperAscii(string s)
Parameters
sstringThe string to be checked.
Returns
- bool
If the given string was
null, thenfalseis returned. If the given string was empty, thentrueis returned. If the string contains only upper ASCII characters in the range 'A' through 'Z', thentrueis returned, otherwisefalseis returned.
IsValidHostID(string)
Determines whether the given HostID is syntactically correct. It does not validate whether the HostID is a known HostID.
public static bool IsValidHostID(string sHostID)
Parameters
sHostIDstringA HostID or
null.
Returns
- bool
If the HostID looks like a valid HostID, then
trueis returned. If the HostID is invalid ornull, thenfalseis returned.
IsValidHostURL(string)
public static bool IsValidHostURL(string sHostURL)
Parameters
sHostURLstring
Returns
IsValidID(string)
Validates the ID of an EBICS party, i.e. a UserID, PartnerID or SystemID.
public static bool IsValidID(string sID)
Parameters
sIDstringThe ID to validate. If this is
null, thenfalsewill be returned.
Returns
- bool
If the ID has a valid syntax, then
trueis returned. Otherwisefalseis returned.
Remarks
Older EBICS versions did only allow up to eight upper case characters and digits in IDs according to the pattern [A-Z0-9]{1,8}. Since EBICS 2.4 the allowed range was extended according to the pattern [a-zA-Z0-9,=]{1,35}. This method validates the ID according to the new pattern.
IsValidIDChar(char)
A valid ID consists of up to 35 valid ID chars.
public static bool IsValidIDChar(char ch)
Parameters
chchar
Returns
Remarks
Older EBICS versions did only allow up to eight upper case characters and digits in IDs according to the pattern [A-Z0-9]{1,8}. Since EBICS 2.4 the allowed range was extended according to the pattern [a-zA-Z0-9,=]{1,35}. This method validates the ID according to the new pattern.
IsValidOrderID(string)
public static bool IsValidOrderID(string sOrderID)
Parameters
sOrderIDstring
Returns
IsValidOrderType(string)
public static bool IsValidOrderType(string sOrderType)
Parameters
sOrderTypestring
Returns
- bool
Returns
trueif, and only if, the parameter is non-null and a syntactically correct order type that consists of exactly three upper case letters in the range from A-Z or digits.
NextSibling(XmlElement)
Get next XML sibling element with the same name.
public static XmlElement NextSibling(XmlElement xmlElement)
Parameters
xmlElementXmlElementThe XML element from which to find the next sibling with the same name. This must not be
null.
Returns
- XmlElement
If another sibling XML element is found, then it is returned. If there is no adjacent XML element sibling with the same name, then
nullis returned.
Remarks
This methods simplifies walking over a sequence of similar XML elements. While looking for the next XML element sibling it skips over all whitespace and comment nodes that may appear in between.
ParseDate(string)
Tries to parse a given ISO 8601 date representation.
public static DateTime ParseDate(string sDate)
Parameters
sDatestringThe date string to be parsed. Only the date portion of this string is parsed, any time specification is ignored. If the parameter is
null, then the value DateTime.MinValue is returned.
Returns
Exceptions
ParseDateTime(string)
Parses an ISO date and time specification with time zone information.
public static DateTime ParseDateTime(string sDateTime)
Parameters
sDateTimestringThe string to parse. Whitespace will be trimmed from this string, before it is parsed. If the resulting string is
nullor empty, thenDateTime.MinValuewill be returned.
Returns
Exceptions
- FormatException
The parameter
sDateTimecontains a malformed ISO date string.
SetAttribute(XmlElement, string, string)
public static void SetAttribute(XmlElement xmlElement, string sAttributeName, string sAttributeValue)
Parameters
xmlElementXmlElementsAttributeNamestringsAttributeValuestring
Squeeze(string)
Removes all the whitespaces in the specified string and returns the cleaned string.
public static string Squeeze(string s)
Parameters
sstring
Returns
- string
If the parameter was
null, then this method returnsnull. In any other case, it returnes the cleaned, maybe all empty, string.
StreamToXml(Stream)
public static XmlDocument StreamToXml(Stream aStream)
Parameters
aStreamStreamStream to read XML document from. This stream will not be closed.
Returns
Trim(string)
Trims whitespace from a string.
public static string Trim(string s)
Parameters
sstringString to be trimmed. May be
null.
Returns
- string
If the parameter s was
null, thennullis returned, otherwise the trimmed string is returned. If the given string consists solely of whitespace, then an empty string will be returned.
- See Also
Trim(string, int)
Trims whitespace from a string.
public static string Trim(string s, int nMaxLength)
Parameters
sstringString to be trimmed. May be
null.nMaxLengthintThe max length of the trimmed string to be returned. If the string is longer than this max length, then it is truncated at the max length.
Returns
TryParseDateTime(string)
Tries to parse an ISO date and time specification with time zone information.
public static DateTime TryParseDateTime(string sDateTime)
Parameters
sDateTimestringThe string to parse. Whitespace will be trimmed from this string, before it is parsed. If the resulting string is
nullor empty, thenDateTime.MinValuewill be returned.
Returns
Remarks
This method does not throw an exception, when the given
sDateTime is malformed. Instead it just returns
DateTime.MinValue.
XmlToBytes(XmlDocument)
public static byte[] XmlToBytes(XmlDocument xmlDocument)
Parameters
xmlDocumentXmlDocument
Returns
- byte[]
XmlToData(XmlDocument)
Serializes an XML document into a raw data buffer.
public static EbicsDataBuffer XmlToData(XmlDocument xmlDocument)
Parameters
xmlDocumentXmlDocument
Returns
Exceptions
- ArgumentNullException
The given parameter was
null.
XmlToStream(XmlDocument, Stream)
Serializes an XML document into the given byte stream.
public static void XmlToStream(XmlDocument xmlDocument, Stream aStream)
Parameters
xmlDocumentXmlDocumentaStreamStreamThe stream to write the XML document to. This stream will not be closed!
Remarks
The document will be written using UTF-8 encoding and will not have a byte order mark.