String decryptString(String str)

Source

static String decryptString(String str) {
  if (str.startsWith('\u001Bpw:')) {
    _encryptEngine.reset();
    _encryptEngine.init(false, _encryptParams);
    String rslt = UTF8.decode(_encryptEngine.process(Base64.decode(str.substring(4))));
    int pos = rslt.indexOf('\u0000');
    if (pos >= 0) rslt = rslt.substring(0, pos);
    return rslt;
  } else if (str.length == 22) {
    // a workaround for the broken password database, need to be removed later
    // 22 is the length of a AES block after base64 encoding
    // encoded password should always be 24 or more bytes, and a plain 22 bytes password is rare
    try{
      _encryptEngine.reset();
       _encryptEngine.init(false, _encryptParams);
       String rslt = UTF8.decode(_encryptEngine.process(Base64.decode(str)));
       int pos = rslt.indexOf('\u0000');
       if (pos >= 0) rslt = rslt.substring(0, pos);
       return rslt;
    } catch(err) {
      return str;
    }
  } else {
    return str;
  }
}