Need help for "Salted with HMAC SHA512 Encryption & Decryption algorithm" code

Dear Techies,
            I have to encrypt & decrypt my password in HMAC SHA512 with salt (have to pass our custom secret keycode). 

Sample C# code:
public static String encryptSHA_512_andSalt(String password, String keyString) {
  String digest = null;
  try {
   String algo = "HmacSHA512";

   SecretKeySpec key = new SecretKeySpec(keyString.toUpperCase().getBytes("UTF-8"), algo);
   Mac mac = Mac.getInstance(algo);
   mac.init(key);

   byte[] bytes = mac.doFinal(password.getBytes("ASCII"));

   StringBuffer hash = new StringBuffer();
   for (int i = 0; i < bytes.length; i++) {
    String hex = Integer.toHexString(0xFF & bytes[i]);
    if (hex.length() == 1) {
     hash.append('0');
    }
    hash.append(hex);
   }
   digest = hash.toString();
  } catch (Exception e) {
  }
  return digest;
 }

 ======== While integrating the above C# code in Integration Studio it throws error ==========

Extension.cs(21,4): error CS0246: The type or namespace name 'SecretKeySpec' could not be found (are you missing a using directive or an assembly reference?)
Extension.cs(21,28): error CS0246: The type or namespace name 'SecretKeySpec' could not be found (are you missing a using directive or an assembly reference?)
Extension.cs(21,54): error CS1061: 'string' does not contain a definition for 'toUpperCase' and no extension method 'toUpperCase' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Extension.cs(22,4): error CS0246: The type or namespace name 'Mac' could not be found (are you missing a using directive or an assembly reference?)
Extension.cs(22,14): error CS0103: The name 'Mac' does not exist in the current context
Extension.cs(25,42): error CS1061: 'string' does not contain a definition for 'getBytes' and no extension method 'getBytes' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Extension.cs(27,4): error CS0246: The type or namespace name 'StringBuffer' could not be found (are you missing a using directive or an assembly reference?)
Extension.cs(27,28): error CS0246: The type or namespace name 'StringBuffer' could not be found (are you missing a using directive or an assembly reference?)
Extension.cs(28,30): error CS1061: 'System.Array' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)
Extension.cs(29,18): error CS0103: The name 'Integer' does not exist in the current context
Extension.cs(30,13): error CS1061: 'string' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

I would like to know how to encrypt & decrypt the login credentials with my own secret keyword.Can anyone assist with the above sample C# code?



Hello Gurubaran,

Did you pass this training? There described how to correctly write extentions.

Hi,

Hope this article can help you.

Also try using the tips from Visual Studio.