AuthorizeNet / inperson-sdk-android

Mobile SDK for Android point-of-sale applications
Other
23 stars 41 forks source link

MSR Head Card Swipe payment Info #18

Open prawal opened 7 years ago

prawal commented 7 years ago

AuthorizeNet/inperson-sdk-android => got error like java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.bbpos.emvswipe.ui/settings.txt: open failed: ENOENT (No such file or directory)

we want to use authorize.net sdk in Android application but didn't get any working sample application(demo). so need your help how to use authorize.net for American Express ,Discover ,JCB ,Diners Club/ Carte Blanch ,Visa ,Master Card and on-line bank transaction so need your help devlope authorize.net sdk in our app for payment.

so we need your help for use authorize.net sdk in our app. which sdk is better AuthorizeNet/inperson-sdk-android or AuthorizeNet/accept-sample-android ? please provide any working sample code (demo)

Also, we are able to see transaction amount and cancel transaction button , in centre of UI we have status textbox but its not changing.Let us know what we need to do here.

Please help us

brianmc commented 7 years ago

Do you want to do an in-person transaction or an in-app transaction? For example, will the application be a merchant's application, will the cardholder be present? Will the application have a card reader attached to the device?

Brian

prawal commented 7 years ago

As I am working on car parking app, and we can swipe the card and make the transaction. Yes we have N5Scan device which will swipe the card. Right now we are getting the encoded data, but not able to do the transaction. In your sample app, there is below code, I m integrating as per requirement, but not able to get response. EMVTransaction emvTransaction = EMVTransactionManager.createEMVTransaction(AppManager.merchant, new BigDecimal(10.1)); emvTransaction.setEmvTransactionType(EMVTransactionType.PAYMENT); emvTransaction.setOrder(order); emvTransaction.setCreditCard(creditCard); EMVTransactionManager.startEMVTransaction(emvTransaction, iemvTransaction, context);

Please mail the working source-code so that i can easily integrate the authorization.net sdk successfully.

Thanks

ptaneja commented 7 years ago

Hello Prawal, Our SDK supports AnyWhereCommerce C2X device reader. To integrate with device you must obtain device from our website https://partner.posportal.com/authorizenet/auth/credit-card-readers/anywherecommerce-walker-c2x-for-authorizenet.html. We don't support N5Scan. thanks

ptaneja commented 7 years ago

Shuttle.txt Please follow the steps mentioned in the attached file. EMVTransactionManager class is only for EMV/Chip Reader/AnyWhereCommerce device.

prawal commented 7 years ago

Hi,

Thanks for sharing the shuttle text file with me. Attaching one class file for your reference, Please extract the file you will get java class , while executing that I am getting below error xml response. Please review the class and let me know where i am wrong. LoginActivity.java.tar.gz

Response : <?xml version="1.0" encoding="UTF-8"?>

Error E00000 Unknown error : null
ptaneja commented 7 years ago

Looks like attachment failed. Could you please share code snippet here.

prawal commented 7 years ago

package com.example.atulkumar.testauth;

import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;

import com.twotechnologies.n5library.MagneticStripeReader.MSRSecurity; import com.twotechnologies.n5library.client.MSRDataListener;

import net.authorize.Environment; import net.authorize.Merchant; import net.authorize.TransactionType; import net.authorize.aim.cardpresent.DeviceType; import net.authorize.aim.cardpresent.MarketType; import net.authorize.auth.PasswordAuthentication; import net.authorize.auth.SessionTokenAuthentication; import net.authorize.data.Order; import net.authorize.data.OrderItem; import net.authorize.data.creditcard.CreditCard; import net.authorize.data.swiperdata.SwiperEncryptionAlgorithmType; import net.authorize.data.swiperdata.SwiperModeType; import net.authorize.data.swiperdata.SwiperOperationType;

import java.math.BigDecimal; import java.util.Arrays;

public class LoginActivity extends Activity {

EditText userName, password;
Button login_btn;
String userId, pwd;
ProgressDialog pd;

net.authorize.mobile.Result loginResult;
Merchant testMerchant;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    userName = (EditText) findViewById(R.id.userName);
    password = (EditText) findViewById(R.id.passWord);
    login_btn = (Button) findViewById(R.id.login_btn);

    login_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            userId = userName.getText().toString();
            pwd = password.getText().toString();

            new Creditcard().execute();

        }
    });

}

private class Creditcard extends AsyncTask<Void, Void, Void>{

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        pd = ProgressDialog.show(LoginActivity.this, "Please wait", "Loading...");

    }

    @Override
    protected Void doInBackground(Void... voids) {

        //Create authentication method based on login, password and device ID
        PasswordAuthentication passAuth = PasswordAuthentication.createMerchantAuthentication(userId, pwd, "1c86dcd87b1dab59c08389c37f9ca5bb5adf1c7ec15b2c3f97801dbd");
        //Create merchant object using authentication method
        testMerchant = Merchant.createMerchant(Environment.SANDBOX, passAuth);
        testMerchant.setDeviceType(DeviceType.WIRELESS_POS);
        testMerchant.setMarketType(MarketType.RETAIL);
        //Create login request and populate mobile device field
        net.authorize.mobile.Transaction loginTransaction = testMerchant.createMobileTransaction(net.authorize.mobile.TransactionType.MOBILE_DEVICE_LOGIN);
        net.authorize.data.mobile.MobileDevice mobileDevice = net.authorize.data.mobile.MobileDevice.createMobileDevice("1c86dcd87b1dab59c08389c37f9ca5bb5adf1c7ec15b2c3f97801dbd", "IDTech", "425-555-0000", "Android");
        loginTransaction.setMobileDevice(mobileDevice);
        //post login request to Authorize.net Gateway
        loginResult = (net.authorize.mobile.Result) testMerchant.postTransaction(loginTransaction);

        Log.e("Result", loginResult.getXmlResponse());
        Log.e("Request", loginResult.getRequestTransaction().toAuthNetPOSTString());

        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);

        pd.dismiss();

        if (loginResult.isOk()) {
            //if login succeeded, populate session token in the Merchant object
            SessionTokenAuthentication sessionTokenAuthentication = SessionTokenAuthentication.createMerchantAuthentication(testMerchant.getMerchantAuthentication().getName(), loginResult.getSessionToken(), "1c86dcd87b1dab59c08389c37f9ca5bb5adf1c7ec15b2c3f97801dbd");
            if ((loginResult.getSessionToken() != null) && (sessionTokenAuthentication != null)) {
                testMerchant.setMerchantAuthentication(sessionTokenAuthentication);
            }
            //create new credit card object and populate it with the encrypted card data coming from the reader
            CreditCard creditCard = CreditCard.createCreditCard();
            creditCard.setCardPresenseType(net.authorize.data.creditcard.CreditCardPresenceType.CARD_PRESENT_ENCRYPTED);
            creditCard.getSwipperData().setMode(SwiperModeType.DATA);
            //the following field is the data converted into HEX string coming from the reader
            creditCard.getSwipperData().setEncryptedData("029800801d3d00008181252a343736312a2a2a2a2a2a2a2a303037365e4341524420372f5649534120544553545e313731322a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a3f2a61fb0d284f736a9f9874e72b74876ca176ab82f6d80cccf40f2af7990a97d89b1f1a525cb23fea37e7b20875b4f133413c0ea7f695110927d7cfc6528fe25e95543133333030343638316299490100000200047635dd03");
            //the FID for the reader
            creditCard.getSwipperData().setDeviceInfo("4649443d4944544543482e556e694d61672e416e64726f69642e53646b7631");
            //the Encryption method used by the reader, should be TDES for IDTech
            creditCard.getSwipperData().setEncryptionAlgorithm(SwiperEncryptionAlgorithmType.TDES);

            //create order item and add to transaction object
            Order order =  Order.createOrder();
            OrderItem oi =  OrderItem.createOrderItem();
            oi.setItemId("001");
            oi.setItemName("Services");
            oi.setItemDescription("Services");
            oi.setItemPrice(new BigDecimal(1.1));
            oi.setItemQuantity("1");
            oi.setItemTaxable(false);
            order.addOrderItem(oi);
            order.setTotalAmount(new BigDecimal(1.1));

            //To test other transaction types, we can change the transaction type enum
            net.authorize.aim.Transaction authCaptureTransaction = testMerchant.createAIMTransaction(TransactionType.AUTH_CAPTURE, order.getTotalAmount());
            authCaptureTransaction.setCreditCard(creditCard);
            authCaptureTransaction.setOrder(order);

            //post the transaction to Gateway
            net.authorize.aim.Result authCaptureResult = (net.authorize.aim.Result) testMerchant.postTransaction(authCaptureTransaction);
            //you can do additional logging on the result object
            //assertTrue(authCaptureResult.isApproved());

            Log.e("Result Final", authCaptureResult.getXmlResponse());
            Log.e("Request Transaction", authCaptureResult.getRequestTransaction().toAuthNetPOSTString());

        } else {
            //handle login errors in here
        }

    }
}

}

ywang7 commented 7 years ago

Hi Pawan,

Looks like there are 2 issues for your case:

  1. login gets error E00000: would you please check the network settings on the phone/simulator? Please try using direct connection instead of proxy if you are using it.
  2. blob coming from the reader not getting accepted by Authorize.net: the format of the test blob is not in the expected format, sample hex encoded blob coming from IDTech Shuttle: 02e300801f3d23008383252a343736312a2a2a2a2a2a2a2a303037365e4341524420372f5649534120544553545e313731322a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a3f2a3b343736312a2a2a2a2a2a2a2a303037363d313731322a2a2a2a2a2a2a2a2a2a2a3f2abdc6bf66f166e542230f16ded5c9d777aceb532e93a34f719a74bb82f10a26ed8492c1e19cd30aaaa366ad4ddc89996b31e0a08293f4048472f7e85019172be48e7fe9b1e8a46ecb740cf2d7e8e2cd2d56b89e693389bf7882286c1454817ded39da65002686d30f34313754303238373430629949010020002002aabf3b03 you may actually try with this blob and it will give you approved result. This is due to the way reader encrypt the data is different compared to the supported model. Currently we support IDTech Shuttle, for more details please visit https://partner.posportal.com/authorizenet/auth/

Please let me know if this solves the problem.

Thanks, Alex

prawal commented 7 years ago

Hi,

Now I am getting the same response as I mentioned above, I am attaching my request in text file, Please have a look and let me know my mistake.

Thanks Pawan Request.txt

ywang7 commented 7 years ago

Hi,

Please find the attached sample request and response for authCapture transaction posting to apitest.authorize.net

Resquest

<?xml version="1.0" encoding="UTF-8" standalone="no"?><createTransactionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><merchantAuthentication><name>MobileCNP1</name><sessionToken>dCVDoRsGWEB6zq6YC1aMiWBGOCfDEA036fQg4wY5UQqjrF6ypeSm5Z4D8cSZP5IHkev2oSP1GZLl$9HTr40LrRh1hiiZfaxXap$tDUzs81Y75kF_tJwi7TA5reSFzLgvX2d8A5TB9SmqOOZHis6HBgAA</sessionToken><mobileDeviceId>Test EMV Android</mobileDeviceId></merchantAuthentication><transactionRequest><transactionType>authCaptureTransaction</transactionType><amount>1.10</amount><payment><encryptedTrackData><FormOfPayment><Value><Encoding>Hex</Encoding><EncryptionAlgorithm>TDES</EncryptionAlgorithm><Scheme><DUKPT><Operation>DECRYPT</Operation><Mode><Data>1</Data></Mode><DeviceInfo><Description>4649443d4944544543482e556e694d61672e416e64726f69642e53646b7631</Description></DeviceInfo><EncryptedData><Value>02e300801f3d23008383252a343736312a2a2a2a2a2a2a2a303037365e4341524420372f5649534120544553545e313731322a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a3f2a3b343736312a2a2a2a2a2a2a2a303037363d313731322a2a2a2a2a2a2a2a2a2a2a3f2abdc6bf66f166e542230f16ded5c9d777aceb532e93a34f719a74bb82f10a26ed8492c1e19cd30aaaa366ad4ddc89996b31e0a08293f4048472f7e85019172be48e7fe9b1e8a46ecb740cf2d7e8e2cd2d56b89e693389bf7882286c1454817ded39da65002686d30f34313754303238373430629949010020002002aabf3b03</Value></EncryptedData></DUKPT></Scheme></Value></FormOfPayment></encryptedTrackData></payment><order/><lineItems><lineItem><itemId>001</itemId><name>testItem</name><description>Goods</description><quantity>1.0000</quantity><unitPrice>1.10</unitPrice></lineItem></lineItems><customer/><billTo/><shipTo/><retail><marketType>2</marketType><deviceType>7</deviceType></retail><transactionSettings><setting><settingName>allowPartialAuth</settingName><settingValue>false</settingValue></setting><setting><settingName>emailCustomer</settingName><settingValue>false</settingValue></setting><setting><settingName>recurringBilling</settingName><settingValue>false</settingValue></setting><setting><settingName>testRequest</settingName><settingValue>false</settingValue></setting></transactionSettings><userFields/></transactionRequest></createTransactionRequest>

Response

<?xml version="1.0" encoding="utf-8"?><mobileDeviceLoginResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><sessionToken>dCVDoRsGWEB6zq6YC1aMiWBGOCfDEA036fQg4wY5UQqjrF6ypeSm5Z4D8cSZP5IHkev2oSP1GZLl$9HTr40LrRh1hiiZfaxXap$tDUzs81Y75kF_tJwi7TA5reSFzLgvX2d8A5TB9SmqOOZHis6HBgAA</sessionToken><merchantContact><merchantName>Mobile Demo</merchantName><merchantAddress>100 4th Street </merchantAddress><merchantCity>redmond</merchantCity><merchantState>WA</merchantState><merchantZip>98052</merchantZip><merchantPhone>425-555-1212</merchantPhone></merchantContact><userPermissions><permission><permissionName>Submit_Charge</permissionName></permission><permission><permissionName>Submit_Refund</permissionName></permission><permission><permissionName>Submit_Update</permissionName></permission><permission><permissionName>API_Merchant_BasicReporting</permissionName></permission><permission><permissionName>Mobile_Admin</permissionName></permission></userPermissions><merchantAccount><marketType>0</marketType><deviceType>7</deviceType></merchantAccount></mobileDeviceLoginResponse>

Thanks, Alex

prawal commented 7 years ago

Hi,

My request is same as you sent in above comment but , I am not getting the expected result. Please let me know what will be the quick-fix here. Do i need to check my account settings.

Thanks Pawan

ywang7 commented 7 years ago

Could you please paste the xml request/response for both login and create transaction?

prawal commented 7 years ago

Hi, Please find the attached text file for xml result and request for login and transactions: XMLRequest.docx

Please have a look and let me know where i am not right. Note: I am sending my Sandbox credential for making a login request, Also we are not sure what we need to pass in Mobile device id, As of now we are assuming the mobile device id from your code.

Thanks Pawan

larryoc commented 7 years ago

We are dealing with a few parallel issues here. Our current release SDK supports both ID Tech Shuttles for MSR only transactions, and Anywhere Commerce Walker C2X readers for EMV, Quick Chip and MSR for non chip cards. When either product is purchased through POSPortal

[http://buy.posportal.com/catalogsearch/result/?q=ID+Tech+Mag+authorize.net]

the device will come with a usable configuration and correct DUKPT keys. The device you are working with may work properly, but we haven't tested it. There may be payload differences, OR we may not be able to decrypt foreign encryption.

Would it be possible to explore acquiring a tested device where the team will have a better grasp of the variables, and can be quicker in addressing the issues?

Thank you for considering!!

prawal commented 7 years ago

Hi Please find attached screenshot screenshot from 2017-04-04 15 31 22

, please let me know what i need to do here.

prawal commented 7 years ago

I am still stucking, and not able to resolve , please have a look at my code and let me know how i can resolve, currently getting E00027 and 380 error code.

package com.example.atulkumar.testauth;

import android.app.Activity; import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; import android.telephony.TelephonyManager; import android.util.Log;

import net.authorize.Environment; import net.authorize.Merchant; import net.authorize.TransactionType; import net.authorize.aim.cardpresent.DeviceType; import net.authorize.aim.cardpresent.MarketType; import net.authorize.auth.PasswordAuthentication; import net.authorize.auth.SessionTokenAuthentication; import net.authorize.auth.TransactionKeyAuthentication; import net.authorize.data.Order; import net.authorize.data.OrderItem; import net.authorize.data.creditcard.CreditCard; import net.authorize.data.creditcard.CreditCardPresenceType; import net.authorize.data.swiperdata.SwiperEncryptionAlgorithmType; import net.authorize.data.swiperdata.SwiperModeType;

import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.util.UUID;

public class HomeActivity extends Activity {

net.authorize.mobile.Result loginResult;
Merchant testMerchant;
String deviceId;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, androidId;
    tmDevice = "" + tm.getDeviceId();
    tmSerial = "" + tm.getSimSerialNumber();
    androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
    deviceId = deviceUuid.toString();
    new Creditcard().execute();
}
private class Creditcard extends AsyncTask<Void, Void, Void>{

    @Override
    protected Void doInBackground(Void... voids) {

        //first we need to login
        net.authorize.mobile.Result loginResult;
        //Create authentication method based on login, password and device ID
        PasswordAuthentication passAuth = PasswordAuthentication.createMerchantAuthentication("PRawal123", "Pawandad123", "InpersonSDK-Android-test");
        //TransactionKeyAuthentication passAuth = TransactionKeyAuthentication.createMerchantAuthentication("2J4H9zq8", "9r654mQfjcB9eC4q");
        //Create merchant object using authentication method
        Merchant testMerchant = Merchant.createMerchant(Environment.SANDBOX, passAuth);
        testMerchant.setDeviceType(DeviceType.WIRELESS_POS);
        testMerchant.setMarketType(MarketType.RETAIL);
        //Create login request and populate mobile device field
        net.authorize.mobile.Transaction loginTransaction = testMerchant.createMobileTransaction(net.authorize.mobile.TransactionType.MOBILE_DEVICE_LOGIN);
        net.authorize.data.mobile.MobileDevice mobileDevice = net.authorize.data.mobile.MobileDevice.createMobileDevice("InpersonSDK-Android-test", "Device description", "425-555-0000", "Android");
        loginTransaction.setMobileDevice(mobileDevice);
        //post login request to Authorize.net Gateway
        loginResult = (net.authorize.mobile.Result) testMerchant.postTransaction(loginTransaction);

        if (loginResult.isOk()) {
            //if login succeeded, populate session token in the Merchant object
            SessionTokenAuthentication sessionTokenAuthentication = SessionTokenAuthentication.createMerchantAuthentication(testMerchant.getMerchantAuthentication().getName(), loginResult.getSessionToken(), "InpersonSDK-Android-test");
            if ((loginResult.getSessionToken() != null) && (sessionTokenAuthentication != null)) {
                testMerchant.setMerchantAuthentication(sessionTokenAuthentication);
            }
            //create new credit card object and populate it with the encrypted card data coming from the reader
            CreditCard creditCard = CreditCard.createCreditCard();
            creditCard.setCardPresenseType(CreditCardPresenceType.CARD_PRESENT_ENCRYPTED);
            creditCard.getSwipperData().setMode(SwiperModeType.DATA);
            //the following field is the data converted into HEX string coming from the reader
     /*  HexStringConverter hx= new HexStringConverter();
            try {
                creditCard.getSwipperData().setEncryptedData(hx.stringToHex(Constant.credtirawadata));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }*/
            String IDTechTestBlob= "3032434530313830314634413232303030333942252a353435392a2a2a2a2a2a2a2a333830305e504157414e20524157414c20202020202020202020202020202f5e2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a3f2a3b353435392a2a2a2a2a2a2a2a333830303d2a2a2a2a2a2a2a2a2a2a2a2a2a2a3f2a35343843443545353433463145313945313037454145444532434242384246413730423430374633414234323834363330314335453443323137344534453845354130373730303431453037443934443632313531303133383241344342413535354133313434334443353839354341443332393638433338383634383736454645393535464646423344413930423534394342413137413631334345423139373241443539384446453241333437363145463544424241413039414237443043354232434134333835444131354437333230363331433730434238373138323643464345334144334133444434443539433630413732364532464132454530343239313341344232454538354443434135444338413443384533343436313845393935303138303144393745383443304336324437384135354332413545333130323436303031324230333234323030303237373336463033";
            creditCard.getSwipperData().setEncryptedData(Constant.myData);
            //the FID for the reader
            creditCard.getSwipperData().setDeviceInfo("4649443d4944544543482e556e694d61672e416e64726f69642e53646b7631");
            //the Encryption method used by the reader, should be TDES for IDTech
            creditCard.getSwipperData().setEncryptionAlgorithm(SwiperEncryptionAlgorithmType.TDES);

            //create order item and add to transaction object
            Order order =  Order.createOrder();
            OrderItem oi =  OrderItem.createOrderItem();
            oi.setItemId("2");
            oi.setItemName("hi");
            oi.setItemDescription("Goods");
            oi.setItemPrice(new BigDecimal(2.0));
            oi.setItemQuantity("2");
            oi.setItemTaxable(false);
            order.addOrderItem(oi);
            order.setTotalAmount(new BigDecimal(2.00));

            //To test other transaction types, we can change the transaction type enum
            net.authorize.aim.Transaction authCaptureTransaction = testMerchant.createAIMTransaction(TransactionType.CREDIT, order.getTotalAmount());
            authCaptureTransaction.setCreditCard(creditCard);
            authCaptureTransaction.setOrder(order);

            //post the transaction to Gateway
            net.authorize.aim.Result authCaptureResult = (net.authorize.aim.Result) testMerchant.postTransaction(authCaptureTransaction);
            Log.e("Response", ""+authCaptureResult.getXmlResponse());
            //you can do additional logging on the result object
         //   assertTrue(authCaptureResult.isApproved());
        } else {
            //handle login errors in here
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);

    }
}
private class HexStringConverter
{
    private final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
    private HexStringConverter hexStringConverter = null;

    private HexStringConverter()
    {}

    public HexStringConverter getHexStringConverterInstance()
    {
        if (hexStringConverter==null) hexStringConverter = new HexStringConverter();
        return hexStringConverter;
    }

    public String stringToHex(String input) throws UnsupportedEncodingException
    {
        if (input == null) throw new NullPointerException();
        return asHex(input.getBytes());
    }

    public String hexToString(String txtInHex)
    {
        byte [] txtInByte = new byte [txtInHex.length() / 2];
        int j = 0;
        for (int i = 0; i < txtInHex.length(); i += 2)
        {
            txtInByte[j++] = Byte.parseByte(txtInHex.substring(i, i + 2), 16);
        }
        return new String(txtInByte);
    }

    private String asHex(byte[] buf)
    {
        char[] chars = new char[2 * buf.length];
        for (int i = 0; i < buf.length; ++i)
        {
            chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4];
            chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F];
        }
        return new String(chars);
    }

}

}