Android Open Source - transloadit-Android-sdk Sha Utils






From Project

Back to project page transloadit-Android-sdk.

License

The source code is released under:

MIT License

If you think the Android project transloadit-Android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package hu.szabot.transloadit.utils;
/* w w  w. ja  v  a  2s. c  o  m*/
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

/**Util functions for Transoadit*/
public class ShaUtils
{
  /**
   * Generates and gets SHA1 string based on the passed parameters
   * @param key Key of the hash
   * @param str String to be secured
   * @return The genarated hash in hex format
   * @throws InvalidKeyException Thrown if the key is invalid
   */
    public static String getSha1(String key, String str) throws InvalidKeyException {

      byte[] bytes=null;
      
      try{
        
        SecretKeySpec keySpec = new SecretKeySpec((key).getBytes("UTF-8"), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(keySpec);
        
        bytes = mac.doFinal(str.getBytes("UTF-8"));
        
      }catch (UnsupportedEncodingException e) 
      {
    }catch (NoSuchAlgorithmException e) {
    }
      
      StringBuilder sb=new StringBuilder();
      
      for(byte b: bytes)
      {
        sb.append(String.format("%02x", b));
      }
      
      return sb.toString();

    }
}




Java Source Code List

hu.szabot.transloadit.ApiData.java
hu.szabot.transloadit.IApiRequest.java
hu.szabot.transloadit.IApiResponse.java
hu.szabot.transloadit.ITransloadit.java
hu.szabot.transloadit.TransloaditRequest.java
hu.szabot.transloadit.TransloaditResponse.java
hu.szabot.transloadit.Transloadit.java
hu.szabot.transloadit.assembly.AssemblyBuilder.java
hu.szabot.transloadit.assembly.IAssemblyBuilder.java
hu.szabot.transloadit.assembly.IStep.java
hu.szabot.transloadit.assembly.Step.java
hu.szabot.transloadit.assembly.exceptions.AlreadyDefinedKeyException.java
hu.szabot.transloadit.assembly.exceptions.InvalidFieldKeyException.java
hu.szabot.transloadit.exceptions.FileNotOpenableException.java
hu.szabot.transloadit.exceptions.NotParseableException.java
hu.szabot.transloadit.executor.DefaultHttpExecutor.java
hu.szabot.transloadit.executor.IRequestExecutor.java
hu.szabot.transloadit.executor.ParsedApiData.java
hu.szabot.transloadit.log.TransloaditLogger.java
hu.szabot.transloadit.parser.IRequestParser.java
hu.szabot.transloadit.parser.IResponseParser.java
hu.szabot.transloadit.parser.JSONRequestParser.java
hu.szabot.transloadit.parser.JSONResponseParser.java
hu.szabot.transloadit.utils.ShaUtils.java