/* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License, as published by the Free Software Foundation and * available at http://www.fsf.org/licensing/licenses/lgpl.html, * version 2.1 or above. * * 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 Lesser General Public License for more details. * * Copyright (c) 2001-2009 StrongAuth, Inc. * * $Date: 2009-11-20 15:14:43 -0800 (Fri, 20 Nov 2009) $ * $Revision: 15 $ * $Author: anoor $ * $URL: https://svn.strongauth.com:9443/repos/topaz/trunk/securestrongkeyliteclient/src/securestrongkeyliteclient/Main.java $ * * ********************************************* * 888 * 888 * 888 * 88888b. .d88b. 888888 .d88b. .d8888b * 888 "88b d88""88b 888 d8P Y8b 88K * 888 888 888 888 888 88888888 "Y8888b. * 888 888 Y88..88P Y88b. Y8b. X88 * 888 888 "Y88P" "Y888 "Y8888 88888P' * * ********************************************* * * This client applicationt tests the StrongKey Lite Encryption System's * web-service by calling the encrypt and then the decrypt services over * an HTTPS port. * * This program is meant to be used as an example of how client programs * will call the EncryptionService and encrypt/decrypt application data. * As one can see, if one eliminates checking for parameters and the * looping code, the actual calls to the web-service are trivial. */ package securestrongkeyliteclient; import com.strongauth.strongkeylite.web.EncryptionService; import com.strongauth.strongkeylite.web.Encryption; import com.strongauth.strongkeylite.web.StrongKeyLiteException_Exception; import java.net.MalformedURLException; import java.net.URL; public class Main { /** * Constants */ private static final String ENCRYPTION_SERVICE_WSDL_SUFFIX = "/strongkeyliteWAR/EncryptionService?wsdl"; public static void main(String[] args) throws MalformedURLException { if (args.length < 6) { System.err.println("Usage: java -jar securestrongkeyliteclient.jar https:// E <# of iterations>\n" + " java -jar securestrongkeyliteclient.jar https:// D \n" + " java -jar securestrongkeyliteclient.jar https:// B <# of iterations>"); return; } // Get all parameters into variables String hostport = args[0]; Long did = Long.parseLong(args[1]); String username = args[2]; String password = args[3]; String operation = args[4]; // Local variables String panprefix = "111122223333"; int pansuffix = 0; int iterations = 1; String hmac = null; boolean encrypt = false; boolean decrypt = false; boolean both = false; String PAN = null; String TOKEN = null; // Encrypt only if (operation.equalsIgnoreCase("E")) { pansuffix = Integer.parseInt(args[5]); iterations = Integer.parseInt(args[6]); encrypt = true; } // Decrypt only else if (operation.equalsIgnoreCase("D")) { hmac = args[5]; decrypt = true; } // Encrypt and Decrypt else if (operation.equalsIgnoreCase("B")) { pansuffix = Integer.parseInt(args[5]); iterations = Integer.parseInt(args[6]); both = true; } // Create URL String hosturl = hostport + ENCRYPTION_SERVICE_WSDL_SUFFIX; URL baseUrl = com.strongauth.strongkeylite.web.EncryptionService.class.getResource("."); URL url = new URL(baseUrl, hosturl); // Create EncryptionService and Encryption objects EncryptionService cryptosvc = new EncryptionService(url); Encryption port = cryptosvc.getEncryptionPort(); // Identify what service we are calling and where System.out.println("\nCalling " + cryptosvc.getServiceName().getLocalPart() + " at " + hostport + "...\n"); // Encrypt and Decrypt if (both) { // Call the service for (int i = 1; i <= iterations; i++) { // Convert int to string String lastdigits = Integer.toString(pansuffix); PAN = panprefix + lastdigits; try { // Encrypt the PAN TOKEN = port.encrypt(did, username, password, PAN); System.out.println(i + ". Original value: " + PAN + " Token received: " + TOKEN); } catch (StrongKeyLiteException_Exception ex) { System.err.println("ENCRYPTION FAILED: " + ex.getMessage()); } try { // Now decrypt and verify String pan = port.decrypt(did, username, password, TOKEN); if (PAN.equalsIgnoreCase(pan)) System.out.println("SUCCESS: Original and recovered PANs are identical!"); } catch (StrongKeyLiteException_Exception ex) { System.err.println("DECRYPTION FAILED: " + ex.getMessage()); } // Increment last digits pansuffix++; } } // Encrypt only else if (encrypt) { // Call the service for (int i = 1; i <= iterations; i++) { // Convert int to string String lastdigits = Integer.toString(pansuffix); PAN = panprefix + lastdigits; try { // Encrypt the PAN TOKEN = port.encrypt(did, username, password, PAN); System.out.println(i + ". Original value: " + PAN + " Token received: " + TOKEN); } catch (StrongKeyLiteException_Exception ex) { System.err.println("ENCRYPTION FAILED: " + ex.getMessage()); } // Increment last digits pansuffix++; } } // Decrypt only else if (decrypt) { try { // Now decrypt and verify String pan = port.decrypt(did, username, password, hmac); if (pan != null) System.out.println("SUCCESS: Recovered PAN: " + pan); } catch (StrongKeyLiteException_Exception ex) { System.err.println("DECRYPTION FAILED: " + ex.getMessage()); } } } }