File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed
plugins/system/android/com/foxdebug/system Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,13 @@ async function checksum(data) {
159159 * @returns
160160 */
161161async function checksumText ( text ) {
162- const textUint8 = new TextEncoder ( ) . encode ( text ) ;
163- return await checksum ( textUint8 ) ;
162+ return new Promise ( ( resolve , reject ) => {
163+ cordova . exec (
164+ ( hash ) => resolve ( hash ) ,
165+ ( error ) => reject ( error ) ,
166+ "System" ,
167+ "checksumText" ,
168+ [ text ] ,
169+ ) ;
170+ } ) ;
164171}
Original file line number Diff line number Diff line change 107107import android .graphics .ImageDecoder ;
108108
109109
110+ import org .apache .cordova .*;
111+ import org .json .JSONArray ;
112+ import org .json .JSONException ;
113+
114+ import java .security .MessageDigest ;
115+
116+
110117
111118public class System extends CordovaPlugin {
112119 private static final String TAG = "SystemPlugin" ;
@@ -560,6 +567,33 @@ public void run() {
560567 break ;
561568 case "compare-texts" :
562569 compareTexts (arg1 , arg2 , callbackContext );
570+ break ;
571+ case "checksumText" :
572+
573+ cordova .getThreadPool ().execute (() -> {
574+ try {
575+
576+ MessageDigest digest = MessageDigest .getInstance ("SHA-256" );
577+
578+ byte [] hash = digest .digest (args .getString (0 ).getBytes ("UTF-8" ));
579+
580+ StringBuilder hexString = new StringBuilder ();
581+
582+ for (byte b : hash ) {
583+ String hex = Integer .toHexString (0xff & b );
584+
585+ if (hex .length () == 1 ) hexString .append ('0' );
586+
587+ hexString .append (hex );
588+ }
589+
590+
591+ callbackContext .success (hexString .toString ());
592+ } catch (Exception e ) {
593+ callbackContext .error (e .getMessage ());
594+ }
595+ });
596+
563597 break ;
564598 default :
565599 break ;
You can’t perform that action at this time.
0 commit comments