---
updatedAt: 2025-05-22T17:57:31.000Z
agentTools:
  projectIndex: https://neutronpay.readme.io/llms.txt
---

# Authentication Signature Computation

```node Node
const crypto = require('crypto');

function computeSignature(apiKey, apiSecret, payload) {
  // Create the string to sign
  const stringToSign = `${apiKey}&payload=${payload}`;
  
  // Create HMAC-SHA256 signature
  const signature = crypto
    .createHmac('sha256', apiSecret)
    .update(stringToSign)
    .digest('hex');
    
  return signature;
}

// Example usage
const apiKey = 'your-api-key';
const apiSecret = 'your-api-secret';
const payload = JSON.stringify({"test":"example"});

const signature = computeSignature(apiKey, apiSecret, payload);
console.log('Signature:', signature);

// Add to headers when making a authentication request
const headers = {
  'Content-Type': 'application/json',
  'X-Api-Key': apiKey,
  'X-Api-Signature': signature
};
```

```csharp C#
using System;
using System.Security.Cryptography;
using System.Text;

public class ApiSignature
{
    public static string ComputeSignature(string apiKey, string apiSecret, string payload)
    {
        // Create the string to sign
        string stringToSign = $"{apiKey}&payload={payload}";
        
        // Convert strings to byte arrays
        byte[] keyBytes = Encoding.UTF8.GetBytes(apiSecret);
        byte[] messageBytes = Encoding.UTF8.GetBytes(stringToSign);
        
        // Create HMAC-SHA256 signature
        using (var hmac = new HMACSHA256(keyBytes))
        {
            byte[] hashBytes = hmac.ComputeHash(messageBytes);
            
            // Convert to hexadecimal string
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < hashBytes.Length; i++)
            {
                builder.Append(hashBytes[i].ToString("x2"));
            }
            
            return builder.ToString();
        }
    }
    
    // Example usage
    public static void Main()
    {
        string apiKey = "your-api-key";
        string apiSecret = "your-api-secret";
        string payload = "{\"test\":\"example\"}";
        
        string signature = ComputeSignature(apiKey, apiSecret, payload);
        Console.WriteLine($"Signature: {signature}");
        
        // Add to headers when making a request
       	// request.Headers.Add("X-API-Key", apiKey);
        // request.Headers.Add("X-Api-Signature", signature);
    }
}
```

```go Go
package main

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/hex"
	"fmt"
)

func computeSignature(apiKey, apiSecret, payload string) string {
	// Create the string to sign
	stringToSign := apiKey + "&payload=" + payload
	
	// Create HMAC-SHA256 signature
	h := hmac.New(sha256.New, []byte(apiSecret))
	h.Write([]byte(stringToSign))
	
	// Get result and convert to hexadecimal string
	signature := hex.EncodeToString(h.Sum(nil))
	
	return signature
}

func main() {
	apiKey := "your-api-key"
	apiSecret := "your-api-secret"
	payload := `{"test":"example"}`
	
	signature := computeSignature(apiKey, apiSecret, payload)
	fmt.Println("Signature:", signature)
	
	// Add to headers when making a request
	// req.Header.Add("X-API-Key", apiKey)
	// req.Header.Add("X-Api-Signature", signature)
}
```

```java Java
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;

public class ApiSignature {

    public static String computeSignature(String apiKey, String apiSecret, String payload) throws Exception {
        // Create the string to sign
        String stringToSign = apiKey + "&payload=" + payload;
        
        // Create HMAC-SHA256 signature
        Mac hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKey = new SecretKeySpec(apiSecret.getBytes(StandardCharsets.UTF8), "HmacSHA256");
        hmac.init(secretKey);
        
        byte[] hashBytes = hmac.doFinal(stringToSign.getBytes(StandardCharsets.UTF8));
        
        // Convert to hexadecimal
        StringBuilder hexString = new StringBuilder();
        for (byte b : hashBytes) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1) {
                hexString.append('0');
            }
            hexString.append(hex);
        }
        
        return hexString.toString();
    }
    
    // Example usage
    public static void main(String[] args) {
        try {
            String apiKey = "your-api-key";
            String apiSecret = "your-api-secret";
            String payload = "{\"test\":\"example\"}";
            
            String signature = computeSignature(apiKey, apiSecret, payload);
            System.out.println("Signature: " + signature);
            
            // Add to headers when making a request
            // connection.setRequestProperty("X-API-Key", apiKey);
            // connection.setRequestProperty("X-Api-Signature", signature);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
```

```json Response Example
{"success":true}
```

# Import packages

<!-- node@1 -->
<!-- csharp@1-3 -->
<!-- go@3-8 -->
<!-- java@1-3 -->

Import the crypto module from Node.js standard library to create the HMAC hash.

# Generate HMAC-SHA256 signature

<!-- node@3-15 -->
<!-- csharp@7-30 -->
<!-- go@10-22 -->
<!-- java@7-29 -->

Use the crypto library to create an HMAC-SHA256 hash and convert it to a hexadecimal string.

# Usage example

<!-- node@16-29 -->
<!-- csharp@32-46 -->
<!-- go@24-35 -->
<!-- java@32-48 -->

Demonstrate how to use the function with sample API credentials and payload.