Authentication

API Security Protocol

All API requests must be authenticated with a developer_key in the request. Your API keys carry many privileges, so be sure to keep them secret!

You authenticate to the Eko API by providing your API key in the header of each request.

How to generate developer_key?

Production developer key will be shared after the following is done:

  1. Organization's KYC is completed on Eko's platform (visit https://connect.eko.in)
  2. Integration has been completed on UAT with signoff from Eko team
  3. For UAT, a dummy developer_key can be used from platform credentials section

Security 2.0

To ensure that compromise on one of the authentication i.e your developer_key never leads to any fraud, another solution has been provided which requires clients to send 2 more parameters for each API call:

  1. secret-key
  2. secret-key-timestamp

How to generate the secret-key?

  1. Encode key using base64 encoding technique

  2. Generate current timestamp (in milliseconds since UNIX epoch), i.e. secret-key-timestamp (Check currentmillis.com to understand the timestamp format)

  3. Compute the signature by hashing salt and base64 encoded key using Hash-based message authentication code HMAC and SHA256

  4. Encode the signature using base64 encoding technique and use this as secret-key

<?php

// Initializing key in some variable. You will receive this key from Eko via email
$key = "d2fe1d99-6298-4af2-8cc5-d97dcf46df30";

// Encode it using base64
$encodedKey = base64_encode($key);

// Get current timestamp in milliseconds since UNIX epoch as STRING
// Check out https://currentmillis.com to understand the timestamp format
$secret_key_timestamp = (int)(round(microtime(true) * 1000));

// Computes the signature by hashing the salt with the encoded key 
$signature = hash_hmac('SHA256', $secret_key_timestamp, $encodedKey, true);

// Encode it using base64
$secret_key = base64_encode($signature);

echo $secret_key;

?>
package com.smartkinda.util;

import org.apache.commons.codec.binary.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidKeyException;
import java.util.Date;

public class HmacSHA256 {
	public static final String HMAC_SHA256 = "HmacSHA256";

	public static void activateEKyc()	
	{
		try {

			String secret_key="",secret_key_timestamp="";
			// Initializing key in some variable. You will receive this key from Eko via email
			String key = "d2fe1d99-6298-4af2-8cc5-d97dcf46df30";
			String encodedKey = Base64.encodeBase64String(key.getBytes());
			// Encode it using base64

			// Get secret_key_timestamp: current timestamp in milliseconds since UNIX epoch as STRING
			// Check out https://currentmillis.com to understand the timestamp format
			Date date = new Date();
			secret_key_timestamp = Long.toString(date.getTime());

			// Computes the signature by hashing the salt with the encoded key 
			Mac sha256_HMAC;

			sha256_HMAC = Mac.getInstance(HMAC_SHA256);

			SecretKeySpec signature = new SecretKeySpec(encodedKey.getBytes(), HMAC_SHA256);
			try {
				sha256_HMAC.init(signature);
			} catch (InvalidKeyException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			// Encode it using base64 to get secret-key
			secret_key = Base64.encodeBase64String(sha256_HMAC.doFinal(secret_key_timestamp.getBytes())).trim();

			System.out.println("secret_key : "+secret_key);
			System.out.println("secret_key_timestamp : "+secret_key_timestamp);


		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.Text;
using System.Configuration;

namespace RechargePortal.Models
{
    public class SequrityKeys
    {
        public string secret_key { get; set; }
        public string secret_key_timestamp { get; set; }
    }

    public class Eko
    {
        public string Unique_Order_No { get; set; }
        public string Secrect_Key { get; set; }
        public string secretKeyTimestamp { get; set; }
        public string HashKey { get; set; }

        #region Get Security Key
        public static SequrityKeys GetSequrityKeys
        {
            get
            {
                SequrityKeys objSequrityKeys = new SequrityKeys();

                // call GenerateSequrityKeys static mathod
                objSequrityKeys = GenerateSequrityKeys();

                return objSequrityKeys;
            }
        }
        #endregion

        
        #region Generate Security Key
        private static SequrityKeys GenerateSequrityKeys()
        {
            SequrityKeys sequrityKey = new SequrityKeys();
            sequrityKey.secret_key = "";
            sequrityKey.secret_key_timestamp = "";

            try
            {
                string key = "d2fe1d99-6298-4af2-8cc5-d97dcf46df30"; // you can keep this in your configuration files
                var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(key);
                var encodedKey = System.Convert.ToBase64String(plainTextBytes);
                DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                long dateTimeInMilliseconds = (long)(DateTime.UtcNow - epoch).TotalMilliseconds;
          sequrityKey.secret_key_timestamp = dateTimeInMilliseconds.ToString();

                sequrityKey.secret_key = CalcHMACSHA256Hash(dateTimeInMilliseconds.ToString(), encodedKey);

            }
            catch (Exception ex)
            {
                // Write Exception handling code here....   
            }


            return sequrityKey;
        }


        public static string GenerateHash(string message,string timespan)
        {
            SequrityKeys sequrityKey = new SequrityKeys();
            sequrityKey.secret_key = "";
            sequrityKey.secret_key_timestamp = "";
            string hash = "";
            try
            {
                string key = ConfigurationManager.AppSettings["SecretKey"];
                var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(key);
                var encodedKey = System.Convert.ToBase64String(plainTextBytes);
                hash= CalcHMACSHA256Hash(message, encodedKey);

            }
            catch (Exception ex)
            {
                // Write Exception handling code here....   
            }


            return hash;
        }
        #endregion

        #region Cal hash Mac Eko
        public static string CalcHMACSHA256Hash(string message, string secret)
        {
            try
            {
                secret = secret ?? "";
                var encoding = new System.Text.ASCIIEncoding();
                byte[] keyByte = encoding.GetBytes(secret);
                byte[] messageBytes = encoding.GetBytes(message);
                using (var hmacsha256 = new HMACSHA256(keyByte))
                {
                    byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
                    return Convert.ToBase64String(hashmessage);
                }
            }
            catch (Exception ex)
            {
                // write exception handling code here
                return "";
            }

        }

        #endregion

    }
}

 // CALLING METHOD :

Eko ek = new Models.Eko();

                ek.Unique_Order_No = Uniqurorderno.ToString();

                SequrityKeys ks = Eko.GetSequrityKeys;

                ek.Secrect_Key = ks.secret_key;

                ek.secretKeyTimestamp = ks.secret_key_timestamp;

 

                if (interactiontypeid == 221) // for money transfer

                {

                    string requsetHsh = ek.secretKeyTimestamp + bankMaster.CustomerID + bankMaster.recipientid + amount;

                    ek.HashKey = Eko.GenerateHash(requsetHsh, ek.secretKeyTimestamp);

                }

                else if (interactiontypeid == 149) // for bank addd

                {

                    string requsetHsh = ek.secretKeyTimestamp;

                    ek.HashKey = Eko.GenerateHash(requsetHsh, ek.secretKeyTimestamp);

                }
import hmac
import base64
import hashlib
import time

secret_key_timestamp = str(int(round(time.time()*1000)))
key = 'd2fe1d99-6298-4af2-8cc5-d97dcf46df30'
dig = hmac.new(
   base64.b64encode(key), secret_key_timestamp, hashlib.sha256
).digest()
secret_key = base64.b64encode(dig).decode()

❗️

Note:

The secret-key-timestamp must match with the current time.

📘

How will you get the key for generating secret-key & request-hash?

The key will be provided to you by Eko via email.

key for the Staging Environment

key = d2fe1d99-6298-4af2-8cc5-d97dcf46df30

❗️

Note

If you are using .NET, you should not send overly specific time stamps, due to differing interpretations of how extra time precision should be dropped. To avoid overly specific time stamps, manually construct dateTime objects with no more than millisecond precision.

❗️

Important Note :

Only IP which is in India will be whitelisted while going on the production mode. IP which is present outside India will not be whitelisted as per compliance

Port 25002 and Port 25004 must be opened on your server in order to reach the requests from your server to our production and staging environment respectively and a connection must be made from your server. You can check if connection is being made from your server or not using the telnet command.

The command for staging environment which you have to use: telnet staging.eko.in 25004.
The command for production environment which you have to use: telnet api.eko.in 25002.