On This Page

{#jumplink-list}  
[Markdown](/docs/cybs/en-us/batch/user/all/so/batch-upload/c_Using_Java_Sample_Code_to_Upload_Files/t_Using_Sample_Code_for_Basic_Authentication.md)  
Filter  
FILTER BY TAG

Using Java Sample Code for Basic Authentication {#t_Using_Sample_Code_for_Basic_Authentication}
===============================================================================================

The sample code was developed and tested on a Solaris platform.

1. Replace your Java installation's existing security policy files with the new ones you downloaded from Oracle's site:

   #### ADDITIONAL INFORMATION

   1. Find your existing `US_export_policy.jar` and `local_policy.jar` files in the `$JAVA_HOME/jre/lib/security` directory.
   2. Rename or move your existing files to another directory.
   3. Copy the new `US_export_policy.jar` and `local_policy.jar` files that you downloaded from Oracle to the `$JAVA_HOME/jre/lib/security` directory.
      {#t_Using_Sample_Code_for_Basic_Authentication_ol_cnm_tlj_ptb}
2. Edit the `$JAVA_HOME/jre/lib/security/java.security` file and insert the security provider right after the Oracle provider. Make sure to increment the numbers of the other providers in the list. Your list of security providers will now look similar to this:

   #### ADDITIONAL INFORMATION

   ```
   security.provider.1=sun.security.provider.Sun
   security.provider.3=com.sun.net.ssl.internal.ssl.Provider
   security.provider.4=com.sun.rsajca.Provider
   security.provider.5=com.sun.crypto.provider.SunJCE
   security.provider.6=sun.security.jgss.SunProvider
   ```
3. Import your `Cybersource` Simple Order API .p12 security key into Internet Explorer.

   #### ADDITIONAL INFORMATION {#t_Using_Sample_Code_for_Basic_Authentication_ID-000007cf}

   1. Open an Internet Explorer Web browser, go to **Tools \&gt; Internet Options...** , and click the **Content** tab.
   2. Click **Certificates...**.
   3. Click**Import...** to open the Certificate Import Wizard, and click **Next** to start the Wizard.
   4. Browse to the location of your .p12 security key and click **Next** .  
      For the password for the private key, enter your `Cybersource` merchant ID. For example, if your key is infodev.p12, enter infodev as the password. {#t_Using_Sample_Code_for_Basic_Authentication_step3d}
      {#t_Using_Sample_Code_for_Basic_Authentication_step3d}
   5. On this page, check the **Mark this key as exportable** box and then click **Next**.
   6. Click **Next** on the Certificate Store page.
   7. Click **Finish** and a confirmation that the import was successful appears.
      {#t_Using_Sample_Code_for_Basic_Authentication_ol_grk_f4j_ptb}
      {#t_Using_Sample_Code_for_Basic_Authentication_ID-step-0000001c}
4. Create a key store file to contain your `Cybersource` Simple Order API .p12 security key:

   #### ADDITIONAL INFORMATION

   1. In a Web browser, go to one of these URLs:

      * If you are in test mode and have not gone live with `Cybersource`: **https://batchtest.cybersource.com/upload/UploadBatchFile**
      * If you have gone live with `Cybersource`: **https://batch.cybersource.com/upload/UploadBatchFile**
      * For live transactions in India, https://batch.in.cybersource.com/upload/UploadBatchFile
        {#t_Using_Sample_Code_for_Basic_Authentication_ul_fzx_k4j_ptb}
   2. Go to **File \&gt; Properties**.

   3. Click **Certificates**.

   4. Click the **Certification Path** tab.

   5. Select **DigiCert.com TLS/SSL Certification Authority**.

   6. Click **View Certificate**.

   7. Click the **Detail**s tab.

   8. Click **Copy to File** and then **Next**.

   9. Click **Browse** and navigate to where you want to save the file.

   10. Enter the name that you want to use for the file, such as MyCert. Click **Save** and click **Next**.

   11. Click Finish.  
       Your file, for example `MyCert.cer`, has been created in the location you specified.

   12. Go to `$JAVA_HOME/bin/keytool` and use the J2SE keytool program to create a keystore file that contains this newly created certificate. You must provide a pass phrase for the keystore. You MUST use the same password that you used in Step 3d above. For example, if your p12 key is infodev.p12, the pass phrase must be infodev.  
       To create the keystore, enter this command:

       ```ph codeph
       $JAVA_HOME/bin/keytool -import -file &lt;path to certificate&gt;/
       &lt;name of certificate file&gt; -keystore &lt;name of keystore file&gt;.jks 
       -storepass &lt;pass phrase of keystore&gt;
       ```

       For example:

       ```
       $JAVA_HOME/bin/keytool -import -file /home/bluu/MyCert.cer -
       keystore MyKeystore.jks -storepass myMerchantID
       ```

       If successful, the output will be similar to this example **\[XXX** from 2020 guide**XXX\]** :

       ```keyword
       Owner: CN=batchtest.cybersource.com, OU=Operations, 
       O=Cybersource Corporation, L=Mountain View, ST=California, C=US
       Issuer: CN=Entrust.net Secure Server Certification Authority, 
       OU=(c) 1999 Entrust.net Limited, OU=www.entrust.net/CPS incorp. 
       by ref. (limits liab.), O=Entrust.net, C=US
       Serial number: 374e1b7b
       Valid from: Thu Nov 18 17:15:34 PST 2004 until: Tue Jan 31 
       17:51:24 PST 2006
       Certificate fingerprints:
          MD5:  BE:BF:B0:91:69:C4:7B:10:45:EC:D6:0F:16:AA:3D:77
          SHA1: 07:F8:41:DC:B2:FC:F5:DA:FC:EE:09:7A:33:B8:29:15:31:18
       Trust this certificate? [no]: yes
       Certificate was added to keystore
       ```

       If successful, the output will be similar to this example **\[XXX** needs approval**XXX\]** :

       ```keyword
       Owner: CN=batchtest.cybersource.com, OU=Operations, 
       O=Cybersource Corporation, L=Foster City, ST=California, C=US
       Issuer: CN=DigiCert.com TLS/SSL Certificate Authority, 
       OU=(c) 2022 DigiCert.com Inc, OU=www.digicert.net/legal-repository/security, O=DigiCert.com, C=US
       Serial number: 374e1b7b
       Valid from: Monday Nov 18 17:15:34 PST 2024 until: Sat Jan 31 
       17:51:24 PST 2026
       Certificate fingerprints:
          MD5:  BE:BF:B0:91:69:C4:7B:10:45:EC:D6:0F:16:AA:3D:77
          SHA1: 07:F8:41:DC:B2:FC:F5:DA:FC:EE:09:7A:33:B8:29:15:31:18
       Trust this certificate? [no]: yes
       Certificate was added to keystore
       ```

   {#t_Using_Sample_Code_for_Basic_Authentication_ol_db4_j4j_ptb}

5. Modify the `SSLFileTransfer.props` file with your settings. The file is part of the `Cybersource` download package and looks similar to this example:

   #### ADDITIONAL INFORMATION

   ```keyword
   # Upload host
   host=batchtest.cybersource.com

   # Upload port
   port=&lt;Upload port&gt;

   # Username to log into the Business Center
   bcUserName=&lt;Business Center login name&gt;

   # Password to log into the Business Center
   bcPassword=&lt;Business Center login password&gt;

   # File to upload
   uploadFile=&lt;path to your file&gt;/&lt;file name&gt;

   # Path where to upload it to (provided by Cybersource)
   path=/upload/UploadBatchFile

   # Your Cybersource security key
   key=&lt;key location path&gt;/&lt;key file name&gt;

   # New key store you just created that contains the certificate
   keyStore=&lt;key store location&gt;/&lt;new key store name&gt;

   # Pass phrase is the string you used in -storepass option when you
   # created the key store file earlier
   passPhrase=&lt;pass phrase&gt;
   ```
6. Set the `JAVA_HOME` environment variable to the location in which you installed J2SE. For example:

   #### ADDITIONAL INFORMATION

   `JAVA_HOME=/home/j2se`

7. Include `$JAVA_HOME/bin` in the PATH.

8. Compile and run the sample:

   #### ADDITIONAL INFORMATION

   1. Change to the directory location in which you stored the `Cybersource` sample files.

   2. Type this:

      ```
      javac SSLFileTransfer.java
      java SSLFileTransfer &lt;path to props file&gt;/SSLFileTransfer.props
      ```

      If the upload is successful, the output should look similar to this:

      ```
      HTTP/1.1 200 OK
      Date: Wed, 26 Jan 2020 17:26:31 GMT
      Server: Apache Coyote/1.0
      Content-Type: text/plain
      Content-Length: 0
      X-Cache: MISS from &lt;your host&gt;
      Connection: close
      UPLOAD FILE SUCCESSFUL
      ```

{#t_Using_Sample_Code_for_Basic_Authentication_ol_cg3_kpj_ptb}  
RELATED TO THIS PAGE

