com.google.android.gms.common.util.Hex Java Examples

The following examples show how to use com.google.android.gms.common.util.Hex. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StickerPackPreviewRepository.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@WorkerThread
private Optional<StickerManifestResult> getManifestRemote(@NonNull String packId, @NonNull String packKey) {
  try {
    byte[]                       packIdBytes    = Hex.stringToBytes(packId);
    byte[]                       packKeyBytes   = Hex.stringToBytes(packKey);
    SignalServiceStickerManifest remoteManifest = receiver.retrieveStickerManifest(packIdBytes, packKeyBytes);
    StickerManifest              localManifest  = new StickerManifest(packId,
                                                                      packKey,
                                                                      remoteManifest.getTitle(),
                                                                      remoteManifest.getAuthor(),
                                                                      toOptionalSticker(packId, packKey, remoteManifest.getCover()),
                                                                      Stream.of(remoteManifest.getStickers())
                                                                            .map(s -> toSticker(packId, packKey, s))
                                                                            .toList());

    return Optional.of(new StickerManifestResult(localManifest, false));
  } catch (IOException | InvalidMessageException e) {
    Log.w(TAG, "Failed to retrieve pack manifest.", e);
  }

  return Optional.absent();
}
 
Example #2
Source File: StickerRemoteUriFetcher.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void loadData(@NonNull Priority priority, @NonNull DataCallback<? super InputStream> callback) {
  try {
    byte[]      packIdBytes  = Hex.stringToBytes(stickerUri.getPackId());
    byte[]      packKeyBytes = Hex.stringToBytes(stickerUri.getPackKey());
    InputStream stream       = receiver.retrieveSticker(packIdBytes, packKeyBytes, stickerUri.getStickerId());

    callback.onDataReady(stream);
  } catch (IOException | InvalidMessageException e) {
    callback.onLoadFailed(e);
  }
}
 
Example #3
Source File: StickerUrl.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static boolean isValidHex(String value) {
  try {
    Hex.stringToBytes(value);
    return true;
  } catch (Exception e) {
    return false;
  }
}
 
Example #4
Source File: GenericPaymentIntentBuilder.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private static String buildUriData(String skuId, String packageName, String paymentType,
    String payload) throws UnsupportedEncodingException {
  return "0x" + Hex.bytesToStringUppercase(
      new Gson().toJson(new TransactionData(paymentType, packageName, skuId, payload))
          .getBytes("UTF-8"))
      .toLowerCase();
}
 
Example #5
Source File: UserHelper.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Encode the given username and password to a MD5 {@link String}.
 *
 * @param username The username of the user account.
 * @param password The password of the user account.
 * @return A encoded MD5 {@link String}.
 */
@SuppressFBWarnings({"DM_CONVERT_CASE"})
@SuppressWarnings({"PMD.UseLocaleWithCaseConversions"})
public static String md5(String username, String password) {
    try {
        String credentials = usernameAndPassword(username, password);
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.reset();
        md.update(credentials.getBytes(StandardCharsets.ISO_8859_1));
        return Hex.bytesToStringUppercase(md.digest()).toLowerCase();
    } catch (NoSuchAlgorithmException noSuchAlgorithmException) {
        // noop. Every implementation of Java is required to support MD5
        throw new AssertionError(noSuchAlgorithmException);
    }
}