1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-26 00:27:30 +00:00

make signing simpler shall we

This commit is contained in:
Austin Huang 2021-03-16 19:30:54 -04:00
parent d65fbd4193
commit 9bf72b2781
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F

View File

@ -93,20 +93,16 @@ public final class Utils {
} }
public static Map<String, String> sign(final Map<String, Object> form) { public static Map<String, String> sign(final Map<String, Object> form) {
final String signed = sign(new JSONObject(form).toString()); final String signed = sign(Constants.SIGNATURE_KEY, new JSONObject(form).toString());
if (signed == null) { if (signed == null) {
return null; return null;
} }
final Map<String, String> map = new HashMap<>(); final Map<String, String> map = new HashMap<>();
map.put("ig_sig_key_version", Constants.SIGNATURE_VERSION); map.put("ig_sig_key_version", Constants.SIGNATURE_VERSION);
map.put("signed_body", signed.split("&signed_body=")[1]); map.put("signed_body", signed);
return map; return map;
} }
public static String sign(final String message) {
return sign(Constants.SIGNATURE_KEY, message);
}
public static String sign(final String key, final String message) { public static String sign(final String key, final String message) {
try { try {
final Mac hasher = Mac.getInstance("HmacSHA256"); final Mac hasher = Mac.getInstance("HmacSHA256");
@ -118,7 +114,7 @@ public final class Utils {
if (hex.length() == 1) hexString.append('0'); if (hex.length() == 1) hexString.append('0');
hexString.append(hex); hexString.append(hex);
} }
return "ig_sig_key_version=" + Constants.SIGNATURE_VERSION + "&signed_body=" + hexString.toString() + "." + message; return hexString.toString() + "." + message;
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Error signing", e); Log.e(TAG, "Error signing", e);
return null; return null;