JAVA中pin什么意思_银⾏业加密算法,PIN相关算法(java-国
密)
public class PIN {
/**
* 加密PIN明⽂
*
* @param pin
* @param pan
* @param key
* @return
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
* @throws NoSuchPaddingException
* @throws ShortBufferException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
* @throws InvalidAlgorithmParameterException
* @throws InvalidKeySpecException
* @throws IllegalArgumentException
* @throws SecurityException
* @throws IOException
*/
public static String encrypt(String pin, String pan, String pik)
throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IllegalArgumentException, SecurityException, IOException {
return encrypt(pin, pan, pik, PINFormat.ANSIX98);
}
public static String encrypt(String pin, String pan, String pik, PINFormat format)
throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IllegalArgumentException, SecurityException, IOException {
String pinBlock = Format.formatPin(pin, pan, format);
byte[] cipherPin = ptECB(Convert.hexToByte(pik), Convert.hexToByte(pinBlock));
return Convert.byteToHexStr(cipherPin);
}
/**
* 解密pin密⽂
*
* @param pinBlock
* @param pan
* @param key
* @return
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
* @throws NoSuchPaddingException
* @throws ShortBufferException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
* @throws InvalidAlgorithmParameterException
* @throws InvalidKeySpecException
* @throws IllegalArgumentException
* @throws SecurityException
* @throws IOException
*/
public static String decrypt(String pinBlock, String pan, String pik)
throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IllegalArgumentException, SecurityException, IOException {
return decrypt(pinBlock, pan, pik, PINFormat.ANSIX98);
}
public static String decrypt(String pinBlock, String pan, String pik, PINFormat format)
throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IllegalArgumentException, SecurityException, IOException {
byte[] cipherPin = SM4.decryptECB(Convert.hexToByte(pik), Convert.hexToByte(pinBlock));
String pin = Format.formatPinBack(Convert.byteToHexStr(cipherPin), pan, format);
return pin;
}
/**
* 字符pin加密
*
* @param pin
* @param pik
parameter是什么意思啊* @return
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
* @throws NoSuchPaddingException
* @throws ShortBufferException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
* @throws InvalidAlgorithmParameterException
* @throws InvalidKeySpecException
* @throws IllegalArgumentException
* @throws SecurityException
* @throws IOException
*/
public static String encryptCharPin(String pin, String pik)
throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IllegalArgumentException, SecurityException, IOException {
String pinBlock = Format.formatPin(pin, pin, PINFormat.CHARPIN);
byte[] cipherPin = ptECB(Convert.hexToByte(pinBlock), Convert.hexToByte(pik));
return Convert.byteToHexStr(cipherPin);
}
/**
* 字符pin解密
*
* @param pinBlock
* @param pik
* @return
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
* @throws NoSuchPaddingException
* @throws ShortBufferException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
* @throws InvalidAlgorithmParameterException
* @throws InvalidKeySpecException
* @throws IllegalArgumentException
* @throws SecurityException
* @throws IOException
*/
public static String decryptCharPin(String pinBlock, String pik)
throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IllegalArgumentException, SecurityException, IOException {
byte[] cipherPin = SM4.decryptECB(Convert.hexToByte(pinBlock), Convert.hexToByte(pik));
String pin = Format.formatPinBack(Convert.byteToHexStr(cipherPin), "", PINFormat.CHARPIN);
return pin;
}
//计算pinoffset的10进制对照表
public static final String D_TABLE = "0123456789012345";
/**
* IBM3624计算⾃然PIN
*
* @param pan
* @param pinLength
* @param pvk
* @return
* @throws SecurityException
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
* @throws NoSuchPaddingException
* @throws ShortBufferException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
* @throws InvalidAlgorithmParameterException
* @throws InvalidKeySpecException
* @throws IOException
*/
public static String calculateNaturalPin(String pan, int pinLength, String pvk)
throws SecurityException, InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException {
String formatPan = String.format("%-16s", pan).replace(' ', 'F');
byte[] cipherPan = ptECB(Convert.hexToByte(formatPan), Convert.hexToByte(pvk));
String cpStr = Convert.byteToHexStr(cipherPan);
StringBuilder builder = new StringBuilder("");
for (int i = 0; i < pinLength; i++) {
builder.append(D_TABLE.charAt(Integer.parseInt(cpStr.substring(i, i + 1), 16)));
}
String();
}
/**
* ibm3624计算pinoffset
*
* @param pan
* @param pin
* @param pinLength
* @param pvk
* @return
* @throws Exception
*/
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论