⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basesmadapter.java

📁 POS is a Java&#174 platform-based, mission-critical, ISO-8583 based financial transaction library/fr
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * jPOS Project [http://jpos.org] * Copyright (C) 2000-2008 Alejandro P. Revilla * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program.  If not, see <http://www.gnu.org/licenses/>. */package  org.jpos.security;import org.jpos.core.Configuration;import org.jpos.core.ConfigurationException;import org.jpos.core.ReConfigurable;import org.jpos.util.LogEvent;import org.jpos.util.LogSource;import org.jpos.util.Logger;import org.jpos.util.NameRegistrar;import org.jpos.util.SimpleMsg;import org.jpos.util.NameRegistrar.NotFoundException;/** * <p> * Provides base functionality for the actual Security Module Adapter. * </p> * <p> * You adapter needs to override the methods that end with "Impl" * </p> * @author Hani S. Kirollos * @version $Revision: 2594 $ $Date: 2008-01-22 14:41:31 -0200 (Tue, 22 Jan 2008) $ */public class BaseSMAdapter        implements SMAdapter, ReConfigurable, LogSource {    protected Logger logger = null;    protected String realm = null;    protected Configuration cfg;    private String name;    public BaseSMAdapter () {        super();    }    public BaseSMAdapter (Configuration cfg, Logger logger, String realm) throws ConfigurationException    {        super();        setLogger(logger, realm);        setConfiguration(cfg);    }    public void setConfiguration (Configuration cfg) throws ConfigurationException {        this.cfg = cfg;    }    public void setLogger (Logger logger, String realm) {        this.logger = logger;        this.realm = realm;    }    public Logger getLogger () {        return  logger;    }    public String getRealm () {        return  realm;    }    /**     * associates this SMAdapter with a name using NameRegistrar     * @param name name to register     * @see NameRegistrar     */    public void setName (String name) {        this.name = name;        NameRegistrar.register("s-m-adapter." + name, this);    }    /**     * @return this SMAdapter's name ("" if no name was set)     */    public String getName () {        return  this.name;    }    /**     * @param name     * @return SMAdapter instance with given name.     * @throws NotFoundException     * @see NameRegistrar     */    public static SMAdapter getSMAdapter (String name) throws NameRegistrar.NotFoundException {        return  (SMAdapter)NameRegistrar.get("s-m-adapter." + name);    }    public SecureDESKey generateKey (short keyLength, String keyType) throws SMException {        SimpleMsg[] cmdParameters =  {            new SimpleMsg("parameter", "Key Length", keyLength), new SimpleMsg("parameter",                    "Key Type", keyType)        };        LogEvent evt = new LogEvent(this, "s-m-operation");        evt.addMessage(new SimpleMsg("command", "Generate Key", cmdParameters));        SecureDESKey result = null;        try {            result = generateKeyImpl(keyLength, keyType);            evt.addMessage(new SimpleMsg("result", "Generated Key", result));        } catch (Exception e) {            evt.addMessage(e);            throw  e instanceof SMException ? (SMException) e : new SMException(e);        } finally {            Logger.log(evt);        }        return  result;    }    public SecureDESKey importKey (short keyLength, String keyType, byte[] encryptedKey,            SecureDESKey kek, boolean checkParity) throws SMException {        SimpleMsg[] cmdParameters =  {            new SimpleMsg("parameter", "Key Length", keyLength), new SimpleMsg("parameter",                    "Key Type", keyType), new SimpleMsg("parameter", "Encrypted Key",                    encryptedKey), new SimpleMsg("parameter", "Key-Encrypting Key", kek), new SimpleMsg("parameter", "Check Parity", checkParity)        };        LogEvent evt = new LogEvent(this, "s-m-operation");        evt.addMessage(new SimpleMsg("command", "Import Key", cmdParameters));        SecureDESKey result = null;        try {            result = importKeyImpl(keyLength, keyType, encryptedKey, kek, checkParity);            evt.addMessage(new SimpleMsg("result", "Imported Key", result));        } catch (Exception e) {            evt.addMessage(e);            throw  e instanceof SMException ? (SMException) e : new SMException(e);        } finally {            Logger.log(evt);        }        return  result;    }    public byte[] exportKey (SecureDESKey key, SecureDESKey kek) throws SMException {        SimpleMsg[] cmdParameters =  {            new SimpleMsg("parameter", "Key", key), new SimpleMsg("parameter", "Key-Encrypting Key",                    kek),        };        LogEvent evt = new LogEvent(this, "s-m-operation");        evt.addMessage(new SimpleMsg("command", "Export Key", cmdParameters));        byte[] result = null;        try {            result = exportKeyImpl(key, kek);            evt.addMessage(new SimpleMsg("result", "Exported Key", result));        } catch (Exception e) {            evt.addMessage(e);            throw  e instanceof SMException ? (SMException) e : new SMException(e);        } finally {            Logger.log(evt);        }        return  result;    }    public EncryptedPIN encryptPIN (String pin, String accountNumber) throws SMException {        accountNumber = EncryptedPIN.extractAccountNumberPart(accountNumber);        SimpleMsg[] cmdParameters =  {            new SimpleMsg("parameter", "clear pin", pin), new SimpleMsg("parameter", "account number",                    accountNumber)        };        LogEvent evt = new LogEvent(this, "s-m-operation");        evt.addMessage(new SimpleMsg("command", "Encrypt Clear PIN", cmdParameters));        EncryptedPIN result = null;        try {            result = encryptPINImpl(pin, accountNumber);            evt.addMessage(new SimpleMsg("result", "PIN under LMK", result));        } catch (Exception e) {            evt.addMessage(e);            throw  e instanceof SMException ? (SMException) e : new SMException(e);        } finally {            Logger.log(evt);        }        return  result;    }    public String decryptPIN (EncryptedPIN pinUnderLmk) throws SMException {        SimpleMsg[] cmdParameters =  {            new SimpleMsg("parameter", "PIN under LMK", pinUnderLmk),        };        LogEvent evt = new LogEvent(this, "s-m-operation");        evt.addMessage(new SimpleMsg("command", "Decrypt PIN", cmdParameters));        String result = null;        try {            result = decryptPINImpl(pinUnderLmk);            evt.addMessage(new SimpleMsg("result", "clear PIN", result));        } catch (Exception e) {            evt.addMessage(e);            throw  e instanceof SMException ? (SMException) e : new SMException(e);        } finally {            Logger.log(evt);        }        return  result;    }    public EncryptedPIN importPIN (EncryptedPIN pinUnderKd1, SecureDESKey kd1) throws SMException {        SimpleMsg[] cmdParameters =  {            new SimpleMsg("parameter", "PIN under Data Key 1", pinUnderKd1), new SimpleMsg("parameter",                    "Data Key 1", kd1),        };        LogEvent evt = new LogEvent(this, "s-m-operation");        evt.addMessage(new SimpleMsg("command", "Import PIN", cmdParameters));        EncryptedPIN result = null;        try {            result = importPINImpl(pinUnderKd1, kd1);            evt.addMessage(new SimpleMsg("result", "PIN under LMK", result));        } catch (Exception e) {            evt.addMessage(e);            throw  e instanceof SMException ? (SMException) e : new SMException(e);        } finally {            Logger.log(evt);        }        return  result;    }    public EncryptedPIN translatePIN (EncryptedPIN pinUnderKd1, SecureDESKey kd1,            SecureDESKey kd2, byte destinationPINBlockFormat) throws SMException {        SimpleMsg[] cmdParameters =  {            new SimpleMsg("parameter", "PIN under Data Key 1", pinUnderKd1), new SimpleMsg("parameter",                    "Data Key 1", kd1), new SimpleMsg("parameter", "Data Key 2", kd2),                    new SimpleMsg("parameter", "Destination PIN Block Format", destinationPINBlockFormat)        };        LogEvent evt = new LogEvent(this, "s-m-operation");        evt.addMessage(new SimpleMsg("command", "Translate PIN from Data Key 1 to Data Key 2",                cmdParameters));        EncryptedPIN result = null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -