public byte[] GetKey(string id, out UsbKeyDriveErrorEnum error) { DriveInfo _drive = GetUsbKeyDrives().FirstOrDefault(); string _path = Path.Combine(UsbKeyPath(_drive), id); if (!File.Exists(_path)) { error = UsbKeyDriveErrorEnum.CannotFindKeyOnUsbKeyDrive; return(null); } try { byte[] _key = File.ReadAllBytes(_path); error = UsbKeyDriveErrorEnum.Ok; return(_key); } catch (Exception) { } error = UsbKeyDriveErrorEnum.ExceptionReadingKeyFile; return(null); }
/// <summary> /// requires a single usb drive marked as key drive to be inserted. Other usb drives are allowed as long the do not have the EncrKeys folder /// </summary> public byte[] GetKey(string id, out UsbKeyDriveErrorEnum error) { UsbDriveInfo _driveInfo = new UsbDriveInfo(); if (_driveInfo.GetUsbKeyDrives().Count == 0) { error = UsbKeyDriveErrorEnum.UsbKeyRequiredToOpen; return(null); } if (_driveInfo.GetUsbKeyDrives().Count > 1) { error = UsbKeyDriveErrorEnum.MultipleUsbKeyDrives; return(null); } return(_driveInfo.GetKey(id, out error)); }
/// <summary> /// requires a single usb drive marked as USBKey to be inserted. Other usb drives are allowed as long the do not have the EncrKeys folder /// </summary> public string CreateKey(out UsbKeyDriveErrorEnum error) { UsbDriveInfo _driveInfo = new UsbDriveInfo(); if (_driveInfo.GetUsbKeyDrives().Count == 0) { error = UsbKeyDriveErrorEnum.NoUsbKeyDrives; return(null); } if (_driveInfo.GetUsbKeyDrives().Count > 1) { error = UsbKeyDriveErrorEnum.MultipleUsbKeyDrives; return(null); } return(_driveInfo.CreateKey(out error)); }
/// <summary> /// Requires a single usb drive to be inserted. /// </summary> /// <param name="error"></param> public void CreateUSBKeyContainer(out UsbKeyDriveErrorEnum error) { UsbDriveInfo _driveInfo = new UsbDriveInfo(); if (_driveInfo.GetUsbDrives().Count == 0) { error = UsbKeyDriveErrorEnum.NoUsbDrives; return; } if (_driveInfo.GetUsbDrives().Count > 1) { error = UsbKeyDriveErrorEnum.MultipleUsbDrives; return; } DriveInfo _drive = _driveInfo.GetUsbDrives().First(); _driveInfo.CreateUsbKeyDrive(_drive, out error); }
public bool CreateUsbKeyDrive(DriveInfo driveInfo, out UsbKeyDriveErrorEnum error) { if (IsUsbKeyDrive(driveInfo)) { error = UsbKeyDriveErrorEnum.Ok; return(true); } try { string _path = UsbKeyPath(driveInfo); Directory.CreateDirectory(_path); error = UsbKeyDriveErrorEnum.Ok; return(true); } catch (Exception) { error = UsbKeyDriveErrorEnum.ExceptionCreatingKeyDrive; } return(false); }
public string CreateKey(out UsbKeyDriveErrorEnum error) { string _id = Guid.NewGuid().ToString().Replace("-", ""); byte[] _key = Generate256BitsOfRandomEntropy(); DriveInfo _drive = GetUsbKeyDrives().FirstOrDefault(); string _path = Path.Combine(UsbKeyPath(_drive), _id); try { File.WriteAllBytes(_path, _key); error = UsbKeyDriveErrorEnum.Ok; return(_id); } catch { } error = UsbKeyDriveErrorEnum.ExceptionWritingKeyFile; return(null); }
public string GetMessage(UsbKeyDriveErrorEnum error) => _Messages[error];