Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/lib/installState.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ async function checksum(data) {
* @returns
*/
async function checksumText(text) {
const textUint8 = new TextEncoder().encode(text);
return await checksum(textUint8);
return new Promise((resolve, reject) => {
cordova.exec(
(hash) => resolve(hash),
(error) => reject(error),
"System",
"checksumText",
[text],
);
});
}
31 changes: 31 additions & 0 deletions src/plugins/system/android/com/foxdebug/system/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
import android.graphics.ImageDecoder;


import java.security.MessageDigest;
import java.security.MessageDigest;



public class System extends CordovaPlugin {
private static final String TAG = "SystemPlugin";
Expand Down Expand Up @@ -560,6 +564,33 @@ public void run() {
break;
case "compare-texts":
compareTexts(arg1, arg2, callbackContext);
break;
case "checksumText":

cordova.getThreadPool().execute(() -> {
try {

MessageDigest digest = MessageDigest.getInstance("SHA-256");

byte[] hash = digest.digest(args.getString(0).getBytes("UTF-8"));

StringBuilder hexString = new StringBuilder();

for (byte b : hash) {
String hex = Integer.toHexString(0xff & b);

if (hex.length() == 1) hexString.append('0');

hexString.append(hex);
}


callbackContext.success(hexString.toString());
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
});

break;
default:
break;
Expand Down
Loading