Can I calculate the CVV from the 3 credit card track data? When I scan a card, there is no CVV, just the number, name and service numbers that don't relate to anything else.
-
4That is somewhat the point of the CVV: that it is not in the magstripe. – Mitch Dec 24 '15 at 17:34
The CVV that is on the mag stripe is actually a CVC1 code, which only attempts to verify that the mag stripe details have not been tampered/corrupted. It is not the same as, nor has any relevance to the CVV code printed onto the back of the card (which is formally known as a CVC2 code.
The CVC2 that is printed onto the back of the card is (by design) intended to be viewed with eyes only, and not machine readable.
More reading : https://randomoracle.wordpress.com/2012/08/25/cvv1-cvv2-cvv3-demystifying-credit-card-data-12/
You need two DES keys(CVK's), card no, service code, expiry to generate CVV.
CVV = Fun(CVK1, CVK2, card_no, service_code, expiry_YYMM);
There are three CVV's
CVV1 : in magnetic stripe CVV2 : back of card ICVD : in chip data
Service Code for each CVV differs
Service code for CVV1 : differs according to card type and usage Service code for CVV2 : 000 Service code for ICVD : 999*
I have implemented following CVV generation algorithm
/**
* @param cvk1 : card verification key1
* @param cvk2 : card verification key1
* @param pan : Account No
* @param svc : Service code CVV1(000), ICVV(999), CVV2(custom)
* @param expiry : Expiry date in YYMM format
* @return : CVV
*/
public static final String calculateCVV(final String cvk1, final String cvk2, final String pan, final String svc, final String expiry) {
String input = Strings.padRight(new StringBuilder().append(pan).append(expiry).append(svc), '0', 32);
String data1 = input.substring(0, 16);
String data2 = input.substring(16);
String d1 = DES.encrypt(data1, cvk1, null, MODE.ECB, PADDING.NoPadding);
String d2 = ByteHexUtil.byteToHex(ByteHexUtil.xor(ByteHexUtil.hexToByte(d1), ByteHexUtil.hexToByte(data2)));
String d3 = TripleDES.encrypt(d2, cvk1 + cvk2, null, MODE.ECB, PADDING.NoPadding);
return Decimalizer.decimalizeDigitsFirst(d3, 3);
}
public static final String decimalizeDigitsFirst(String data, final int outLen) {
StringBuilder selected = new StringBuilder(outLen);
int selectionCounter = 0;
int len = data.length();
for(int i=0; i<len && selectionCounter < outLen ; i++){
if(hexToByte(data.charAt(i)) < 10) {
selected.append(data.charAt(i));
selectionCounter++;
}
}
if(selectionCounter !=2) {
for(int i=0; i<len && selectionCounter < outLen ; i++){
if(hexToByte(data.charAt(i)) > 9) {
selected.append(decTable[hexToByte(data.charAt(i))]);
selectionCounter++;
}
}
}
return selected.toString();
}