/* * Copyright 2003 Federal Chancellery Austria * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package at.gv.egovernment.moa.id.auth.builder; import java.security.MessageDigest; import at.gv.egovernment.moa.id.BuildException; import at.gv.egovernment.moa.util.Base64Utils; import at.gv.egovernment.moa.util.Constants; /** * Builder for the bPK, as defined in * "Ableitung f¨r die bereichsspezifische Personenkennzeichnung" * version 1.0.1 from "reference.e-government.gv.at". * * @author Paul Schamberger * @version $Id$ */ public class BPKBuilder { /** * Builds the bPK from the given parameters. * @param identificationValue Base64 encoded "Stammzahl" * @param target "Bereich lt. Verordnung des BKA" * @return bPK in a BASE64 encoding * @throws BuildException if an error occurs on building the bPK */ public String buildBPK(String identificationValue, String target) throws BuildException { if ((identificationValue == null || identificationValue.length() == 0 || target == null || target.length() == 0)) { throw new BuildException("builder.00", new Object[] {"BPK", "Unvollständige Parameterangaben: identificationValue=" + identificationValue + ",target=" + target}); } String basisbegriff = identificationValue + "+" + Constants.URN_PREFIX_CDID + "+" + target; try { MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] hash = md.digest(basisbegriff.getBytes("ISO-8859-1")); String hashBase64 = Base64Utils.encode(hash); return hashBase64; } catch (Exception ex) { throw new BuildException("builder.00", new Object[] {"bPK", ex.toString()}, ex); } } /** * Builds the wbPK from the given parameters. * @param identificationValue Base64 encoded "Stammzahl" * @param registerAndOrdNr type of register + "+" + number in register. * @return wbPK in a BASE64 encoding * @throws BuildException if an error occurs on building the wbPK */ public String buildWBPK(String identificationValue, String registerAndOrdNr) throws BuildException { if ((identificationValue == null || identificationValue.length() == 0 || registerAndOrdNr == null || registerAndOrdNr.length() == 0)) { throw new BuildException("builder.00", new Object[] {"wbPK", "Unvollständige Parameterangaben: identificationValue=" + identificationValue + ",Register+Registernummer=" + registerAndOrdNr}); } String basisbegriff = identificationValue + "+" + Constants.URN_PREFIX_WBPK + "+" + registerAndOrdNr; try { MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] hash = md.digest(basisbegriff.getBytes("ISO-8859-1")); String hashBase64 = Base64Utils.encode(hash); return hashBase64; } catch (Exception ex) { throw new BuildException("builder.00", new Object[] {"wbPK", ex.toString()}, ex); } } }