Can anyone of you please Help me with this Java Code? I have a java code, which i want to convert in C#.

Forums C#Can anyone of you please Help me with this Java Code? I have a java code, which i want to convert in C#.
Staff asked 3 years ago
public static String getShieldSignature(Long timeStamp, String siteId, String shieldSecretKey) {
    String shieldSignature = "";
    try {
        String timeHash = generateHash(timeStamp.toString(), shieldSecretKey);
        shieldSignature = generateHash(siteId, timeHash);
    } catch (GeneralSecurityException e) {
        e.printStackTrace();
    }
    return shieldSignature;
}

private static String generateHash(String toHash, String secretKey) throws GeneralSecurityException {
    SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256");
    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(keySpec);
    byte[] hashBytes = mac.doFinal(toHash.getBytes());
    return Hex.bytesToStringLowercase(hashBytes);
}

 

Subscribe

Select Categories