I'm working on a portion of the codes to encrypt the ATM card of the user.
Public class AtmCardAuth{
public static byte[] computeCheckBytes(int acctNum, int pin)throws Exception {
// byte[] ret = new byte[32];
// for(int i=0; i<ret.length; ++i) ret[i] = (byte)i;
// return ret;
String password = Integer.toString(pin);
String accNumber = Integer.toString(acctNum);
SecretKey key = new SecretKeySpec(password.getBytes(),"DES");
Cipher ecipher = Cipher.getInstance("DES");
ecipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encrypted = ecipher.doFinal(accNumber.getBytes());
return encrypted;
}
}
AtmCardAuth.computeCheckBytes(5,8842378);
The AtmCardAuth function is use to encrypt the user account number and pin number into a card_5.atm file.An error prompt out while running the code, it mentioned "Invalid key length: 7 bytes". Any solution that can solve the problem. The acctNum and pin parameters value must be in integer type in order to complete the codes.