Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Merge pull request #26 from tlei/master
Browse files Browse the repository at this point in the history
Methoden zur Prüfung von Creditor IDs.
  • Loading branch information
willuhn committed Mar 25, 2014
2 parents 1c14431 + dd184de commit abd3d7d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/org/kapott/hbci/manager/AccountCRCAlgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -1612,4 +1612,32 @@ public static boolean checkIBAN(String iban)

return rest.intValue()==1;
}

public static boolean checkCreditorId(String creditorId)
{
//DE: Immer Länge 18
if ("DE".equals(creditorId.substring(0,2).toUpperCase()) && creditorId.length()!=18)
return false;

//Rest wie bei IBAN
StringBuffer s=new StringBuffer();

s.append(creditorId.substring(7));
s.append(creditorId.substring(0,4));

StringBuffer s2=new StringBuffer();
for (int i=0; i<s.length(); i++) {
char ch=s.charAt(i);
if (ch>='0' && ch<='9') {
s2.append(ch);
} else {
s2.append(ch-'A'+10);
}
}

BigInteger x=new BigInteger(s2.toString());
BigInteger rest=x.mod(new BigInteger("97"));

return rest.intValue()==1;
}
}
9 changes: 9 additions & 0 deletions src/org/kapott/hbci/manager/HBCIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,15 @@ public static boolean checkIBANCRC(String iban)
return AccountCRCAlgs.checkIBAN(iban);
}

/** Überprüfen der Gültigkeit einer Gläubiger-ID. Diese Methode prüft anhand eines
* Prüfziffer-Algorithmus, ob die übergebene ID prinzipiell gültig ist.
* @return <code>false</code> wenn der Prüfzifferntest fehlschlägt, sonst
* <code>true</code> */
public static boolean checkCredtitorIdCRC(String iban)
{
return AccountCRCAlgs.checkCreditorId(iban);
}

private static void refreshBLZList(ClassLoader cl)
throws IOException
{
Expand Down
29 changes: 29 additions & 0 deletions test/hbci4java/manager/TestAccountCRCAlgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package hbci4java.manager;

import org.junit.Assert;
import org.junit.Test;
import org.kapott.hbci.manager.AccountCRCAlgs;

public class TestAccountCRCAlgs {

@Test
public void test001() {
//Beispiel Bundesbank
Assert.assertTrue(AccountCRCAlgs.checkCreditorId("DE98ZZZ09999999999"));
//Bund
Assert.assertTrue(AccountCRCAlgs.checkCreditorId("DE09ZZZ00000000001"));
}

//Test, das alle anderen Prüfziffern bei "DE98ZZZ09999999999" falsch sind
@Test
public void test002() {
String prefix="DE";
String postfix="ZZZ09999999999";
for (int i=2; i<98; i++) {
String mid = String.valueOf(i);
if (i<10) mid = "0"+mid;
Assert.assertFalse(prefix+mid+postfix, AccountCRCAlgs.checkCreditorId(prefix+mid+postfix));
}
}

}

0 comments on commit abd3d7d

Please sign in to comment.