code: public void saveCredentials(@NonNull Credentials credentials) throws CredentialsManagerException {
          if ((isEmpty(credentials.getAccessToken()) && isEmpty(credentials.getIdToken())) || credentials.getExpiresAt() == null) {
              throw new CredentialsManagerException("Credentials must have a valid date of expiration and a valid access_token or id_token value.");
          }
  
          String json = gson.toJson(credentials);
          long expiresAt = credentials.getExpiresAt().getTime();
          boolean canRefresh = !isEmpty(credentials.getRefreshToken());
  
          Log.d(TAG, "Trying to encrypt the given data using the private key.");
          try {
              byte[] encrypted = crypto.encrypt(json.getBytes());
              String encryptedEncoded = Base64.encodeToString(encrypted, Base64.DEFAULT);
              storage.store(KEY_CREDENTIALS, encryptedEncoded);
              storage.store(KEY_EXPIRES_AT, expiresAt);
              storage.store(KEY_CAN_REFRESH, canRefresh);
          } catch (IncompatibleDeviceException e) {
              throw new CredentialsManagerException(String.format("This device is not compatible with the %s class.", SecureCredentialsManager.class.getSimpleName()), e);
          } catch (CryptoException e) {
              /*
               * If the keys were invalidated in the call above a good new pair is going to be available
               * to use on the next call. We clear any existing credentials so #hasValidCredentials returns
               * a true value. Retrying this operation will succeed.
               */
              clearCredentials();
              throw new CredentialsManagerException("A change on the Lock Screen security settings have deemed the encryption keys invalid and have been recreated. Please, try saving the credentials again.", e);
          }
      }
docs: Saves the given credentials in the Storage.
  
  @param credentials the credentials to save.
  @throws CredentialsManagerException if the credentials couldn't be encrypted. Some devices are not compatible at all with the cryptographic
  implementation and will have {@link CredentialsManagerException#isDeviceIncompatible()} return true.