Guest User

instagram signed_body

a guest
Jan 22nd, 2013
3,258
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class RequestUtil
  2. {
  3.   public static String SIGNATURE_KEY_VERSION = "4";
  4.   public static String SIGNATURE_KEY_VERSION_FIELD_NAME = "ig_sig_key_version";
  5.   static String sLastValidAlgorithm = null;
  6.  
  7.   public static String generateSignature(String paramString)
  8.   {
  9.     String str1 = NativeBridge.getInstagramString("a4d1b77bbb1a4a5ca695ad72c84b77e5");
  10.     String str3;
  11.     StringBuilder localStringBuilder;
  12.     try
  13.     {
  14.       Mac localMac = getValidMac();
  15.       localMac.init(new SecretKeySpec(str1.getBytes("UTF-8"), localMac.getAlgorithm()));
  16.       byte[] arrayOfByte = localMac.doFinal(paramString.getBytes());
  17.       BigInteger localBigInteger = new BigInteger(1, arrayOfByte);
  18.       String str4 = String.format("%0" + (arrayOfByte.length << 1) + "x", new Object[] { localBigInteger });
  19.       str3 = str4;
  20.       return str3;
  21.     }
  22.     catch (Exception localException)
  23.     {
  24.       localStringBuilder = new StringBuilder().append("failed_to_generate_signature: ");
  25.       if (localException.getMessage() == null);
  26.     }
  27.     for (String str2 = localException.getMessage(); ; str2 = localException.getClass().toString())
  28.     {
  29.       NoopUtil.report(str2);
  30.       str3 = null;
  31.       break;
  32.     }
  33.   }
  34.  
  35.   private static Mac getValidMac()
  36.   {
  37.     if (sLastValidAlgorithm != null);
  38.     while (true)
  39.     {
  40.       try
  41.       {
  42.         Mac localMac2 = Mac.getInstance(sLastValidAlgorithm);
  43.         localObject = localMac2;
  44.         return localObject;
  45.       }
  46.       catch (NoSuchAlgorithmException localNoSuchAlgorithmException2)
  47.       {
  48.       }
  49.       String[] arrayOfString = { "HmacSHA256", "hmacSHA256", "HMAC-SHA256", "hmac-sha256", "HMAC/SHA256", "hmac/sha256" };
  50.       int i = arrayOfString.length;
  51.       int j = 0;
  52.       while (true)
  53.         while (true)
  54.         {
  55.           if (j >= i)
  56.             break label107;
  57.           String str = arrayOfString[j];
  58.           try
  59.           {
  60.             Mac localMac1 = Mac.getInstance(str);
  61.             localObject = localMac1;
  62.             if (localObject != null)
  63.               sLastValidAlgorithm = str;
  64.           }
  65.           catch (NoSuchAlgorithmException localNoSuchAlgorithmException1)
  66.           {
  67.             while (true)
  68.               localObject = null;
  69.             j++;
  70.           }
  71.         }
  72.       label107: Object localObject = null;
  73.     }
  74.   }
  75.  
  76.   public static void setSignedBody(RequestParams paramRequestParams, String paramString)
  77.   {
  78.     String str = null;
  79.     if (paramString != null)
  80.       str = String.format("%s.%s", new Object[] { generateSignature(paramString), paramString });
  81.     paramRequestParams.put("signed_body", str);
  82.     paramRequestParams.put(SIGNATURE_KEY_VERSION_FIELD_NAME, SIGNATURE_KEY_VERSION);
  83.   }
  84. }
RAW Paste Data