File tree Expand file tree Collapse file tree 2 files changed +40
-2
lines changed
plugins/system/android/com/foxdebug/system Expand file tree Collapse file tree 2 files changed +40
-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 java .security .MessageDigest ;
111+ import java .security .MessageDigest ;
112+
113+
110114
111115public class System extends CordovaPlugin {
112116 private static final String TAG = "SystemPlugin" ;
@@ -560,6 +564,33 @@ public void run() {
560564 break ;
561565 case "compare-texts" :
562566 compareTexts (arg1 , arg2 , callbackContext );
567+ break ;
568+ case "checksumText" :
569+
570+ cordova .getThreadPool ().execute (() -> {
571+ try {
572+
573+ MessageDigest digest = MessageDigest .getInstance ("SHA-256" );
574+
575+ byte [] hash = digest .digest (args .getString (0 ).getBytes ("UTF-8" ));
576+
577+ StringBuilder hexString = new StringBuilder ();
578+
579+ for (byte b : hash ) {
580+ String hex = Integer .toHexString (0xff & b );
581+
582+ if (hex .length () == 1 ) hexString .append ('0' );
583+
584+ hexString .append (hex );
585+ }
586+
587+
588+ callbackContext .success (hexString .toString ());
589+ } catch (Exception e ) {
590+ callbackContext .error (e .getMessage ());
591+ }
592+ });
593+
563594 break ;
564595 default :
565596 break ;
You can’t perform that action at this time.
0 commit comments