Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. private static String bytesToStringSign(byte[] bArr) {
  2. StringBuilder stringBuilder = new StringBuilder();
  3. for (byte b : bArr) {
  4. stringBuilder.append(Integer.toString((b & 255) + 256, 16).substring(1));
  5. }
  6. return stringBuilder.toString();
  7. }
  8.  
  9. public static String getSign(File file, String str) throws IOException, NoSuchAlgorithmException {
  10. InputStream fileInputStream;
  11. Throwable th;
  12. MessageDigest instance = MessageDigest.getInstance("SHA-1");
  13. try {
  14. fileInputStream = new FileInputStream(file);
  15. try {
  16. byte[] bArr = new byte[8192];
  17. int read = fileInputStream.read(bArr);
  18. while (read != -1) {
  19. instance.update(bArr, 0, read);
  20. read = fileInputStream.read(bArr);
  21. }
  22. if (read == -1) {
  23. byte[] bytes = str.getBytes();
  24. instance.update(bytes, 0, bytes.length);
  25. }
  26. String a = bytesToStringSign(instance.digest());
  27. if (fileInputStream != null) {
  28. fileInputStream.close();
  29. }
  30. return a;
  31. } catch (Throwable th2) {
  32. th = th2;
  33. if (fileInputStream != null) {
  34. fileInputStream.close();
  35. }
  36. throw th;
  37. }
  38. } catch (Throwable th3) {
  39. th = th3;
  40. fileInputStream = null;
  41. if (fileInputStream != null) {
  42. fileInputStream.close();
  43. }
  44. throw th;
  45. }
  46. }
  47.  
  48. private static String main() {
  49. File image;
  50. String SECRET_STRING = "qwertyuiopasdfghjklzxcvbnmqwertyuiopas";
  51. String result = getSign(image, SECRET_STRING);
  52. }
  53.  
  54. function GetImageSign($input_image) {
  55. // получаем 8192 первых байт данных изображения
  56. $data = substr($input_image['data'], 0, 8192);
  57. // добавляем секретную строку
  58. $data .= '"qwertyuiopasdfghjklzxcvbnmqwertyuiopas"';
  59.  
  60. // полученный Java Hash - db6f43a2e43eec3e3b90ed9dc17df2a409675d64
  61. $ar = sha1($data, true);
  62. $size = strlen($ar);
  63.  
  64. $str = '';
  65. for ($i = 0; $i < $size; $i++) {
  66. $str .= substr(dechex(((int)$ar[$i] & 255) + 256), 2);
  67. }
  68. print_r($str);
  69. die();
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement