@@ -574,38 +574,39 @@ public static void onAuthenticated(boolean withFingerprint,
574574 boolean createdResultJson = false ;
575575
576576 try {
577+ byte [] bytes ;
578+ FingerprintManager .CryptoObject cryptoObject ;
579+
577580 if (withFingerprint ) {
578- // If the user has authenticated with fingerprint, verify that using cryptography and
579- // then return the encrypted (in Base 64) or decrypted mClientSecret
580- byte [] bytes ;
581- if (mCipherModeCrypt ) {
582- bytes = result .getCryptoObject ().getCipher ()
583- .doFinal (mClientSecret .getBytes ("UTF-8" ));
584- String encodedBytes = Base64 .encodeToString (bytes , Base64 .NO_WRAP );
585- resultJson .put ("token" , encodedBytes );
586- } else {
587- bytes = result .getCryptoObject ().getCipher ()
588- .doFinal (Base64 .decode (mClientSecret , Base64 .NO_WRAP ));
589- String credentialString = new String (bytes , "UTF-8" );
590- String [] credentialArray = credentialString .split (":" );
591- if (credentialArray .length == 2 ) {
592- String username = credentialArray [0 ];
593- String password = credentialArray [1 ];
594- if (username .equalsIgnoreCase (mClientId + mUsername )) {
595- resultJson .put ("password" , credentialArray [1 ]);
596- }
597- }
598- }
599581 resultJson .put ("withFingerprint" , true );
582+ cryptoObject = result .getCryptoObject ();
600583 } else {
601- // Authentication happened with backup password.
602584 resultJson .put ("withBackup" , true );
585+ cryptoObject = new FingerprintManager .CryptoObject (mCipher );
603586
604587 // If failed to init cipher because of InvalidKeyException, create new key
605588 if (!initCipher ()) {
606589 createKey ();
607590 }
608591 }
592+
593+ if (mCipherModeCrypt ) {
594+ bytes = cryptoObject .getCipher ().doFinal (mClientSecret .getBytes ("UTF-8" ));
595+ String encodedBytes = Base64 .encodeToString (bytes , Base64 .NO_WRAP );
596+ resultJson .put ("token" , encodedBytes );
597+ } else {
598+ bytes = cryptoObject .getCipher ()
599+ .doFinal (Base64 .decode (mClientSecret , Base64 .NO_WRAP ));
600+ String credentialString = new String (bytes , "UTF-8" );
601+ String [] credentialArray = credentialString .split (":" );
602+ if (credentialArray .length == 2 ) {
603+ String username = credentialArray [0 ];
604+ String password = credentialArray [1 ];
605+ if (username .equalsIgnoreCase (mClientId + mUsername )) {
606+ resultJson .put ("password" , credentialArray [1 ]);
607+ }
608+ }
609+ }
609610 createdResultJson = true ;
610611 } catch (BadPaddingException e ) {
611612 Log .e (TAG , "Failed to encrypt the data with the generated key:"
0 commit comments