get static method

Future<Cred?> get({
  1. required String key,
  2. Type type = Type.CRED_TYPE_GENERIC,
  3. bool encrypted = false,
  4. bool fAsSelf = false,
})

The get (uses CredReadW from wincred.h) function reads a credential from the user's credential set. The credential set used is the one associated with the logon session of the current token. The token must not have the user's SID disabled.

more info and error types https://docs.microsoft.com/en-us/windows/win32/api/wincred/nf-wincred-credreadw#return-value

FlutterWindowsVault.get(
  // the key value you want to return its value
  key: 'password',
  // type: The type of the credential you want to return its value.
  // This member cannot be changed after the credential is created. The values are in Type enum.
  // default value is Type.CRED_TYPE_GENERIC.
  // for more about the types => https://docs.microsoft.com/en-us/windows/win32/api/wincred/ns-wincred-credentiala#members
  type: Type.CRED_TYPE_GENERIC,
  // if the the value you want to get is encrypted
  // default value is false.
  encrypted: true,
  // fAsSelf: (this works only if encrypted is true) Set to TRUE to specify that the credentials are encrypted in the security context of the current process.
  // Set to FALSE to specify that credentials are encrypted in the security context of the calling thread security context.
  // default value is false.
  fAsSelf: false,
);

Implementation

static Future<Cred?> get({
  required String key,
  Type type = Type.CRED_TYPE_GENERIC,
  bool encrypted = false,
  bool fAsSelf = false,
}) async {
  assert(key.isNotEmpty);
  // assert(type != null);
  // assert(encrypted != null);
  // assert(!encrypted || (encrypted && fAsSelf != null));
  assert(!fAsSelf || (fAsSelf && encrypted));

  try {
    return await _channel.invokeMapMethod<String, dynamic>('get', {
      'key': key,
      'type': type.index + 1,
      'encrypted': encrypted,
      'fAsSelf': fAsSelf,
    }).then((data) {
      if (data == null) return null;
      return Cred.fromJson(data);
    });
  } catch (err) {
    if (err is PlatformException && err.code != 'ERROR_NOT_FOUND') throw err;
    return Future<Cred>.value(null);
  }
}