Created
          November 21, 2020 16:43 
        
      - 
      
- 
        Save domdorn/383de1e8b55d091f7096f6b01644f695 to your computer and use it in GitHub Desktop. 
    Create a HMac Sha256 hash from a given string
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | object HMAC { | |
| def generateHMAC(sharedSecret: String, input: String): String = { | |
| val secret = new SecretKeySpec(sharedSecret.getBytes, "HmacSHA256") //Crypto Funs : 'SHA256' , 'HmacSHA1' | |
| val mac = Mac.getInstance("HmacSHA256") | |
| mac.init(secret) | |
| val hashString: Array[Byte] = mac.doFinal(input.getBytes) | |
| // this makes sure that the string is 64chars long and gets padded with 0 if its shorter | |
| String.format("%064x", new BigInteger(1, hashString)) | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment