/// <summary> /// ValidateKey method implementation /// </summary> public override bool ValidateKey(string upn) { if (string.IsNullOrEmpty(upn)) { return(false); } string lupn = upn.ToLower(); string key = ReadKey(lupn); if (HasStorageInfos(key)) { using (var prov = new RNGEncryption(_xorsecret, _mode)) { byte[] crypted = StripStorageInfos(ReadKey(lupn)); if (crypted == null) { return(false); } byte[] cleared = prov.Decrypt(crypted, lupn); if (cleared == null) { return(false); // Key corrupted } if (prov.CheckSum == null) { return(false); // Key corrupted } if (prov.CheckSum.SequenceEqual(CheckSumEncoding.CheckSum(lupn))) { return(true); // OK RSA } else { return(false); // Key corrupted } } } else { return(false); } }
/// <summary> /// EncodedKey method implementation /// </summary> public override string EncodedKey(string upn) { if (string.IsNullOrEmpty(upn)) { return(null); } string lupn = upn.ToLower(); string key = ReadKey(lupn); if (string.IsNullOrEmpty(key)) { return(null); } byte[] cleared = null; using (var prov = new RNGEncryption(_xorsecret, _mode)) { byte[] crypted = StripStorageInfos(key); if (crypted == null) { return(null); } cleared = prov.Decrypt(crypted, lupn); if (cleared == null) { return(null); } } if (cleared.Length > MAX_PROBE_LEN) { byte[] buffer = new byte[MAX_PROBE_LEN]; Buffer.BlockCopy(cleared, 0, buffer, 0, MAX_PROBE_LEN); return(Base32.Encode(buffer)); } else { return(Base32.Encode(cleared)); } }
/// <summary> /// NewKey method implementation /// </summary> public override string NewKey(string upn) { if (string.IsNullOrEmpty(upn)) { return(null); } string lupn = upn.ToLower(); byte[] crypted = null; using (var prov = new RNGEncryption(_xorsecret, _mode)) { crypted = prov.Encrypt(lupn); if (crypted == null) { return(null); } } string outkey = AddStorageInfos(crypted); return(KeysStorage.NewUserKey(lupn, outkey)); }
/// <summary> /// ProbeKey method implmentation /// </summary> public override byte[] ProbeKey(string upn) { if (string.IsNullOrEmpty(upn)) { return(null); } string lupn = upn.ToLower(); string key = ReadKey(lupn); if (string.IsNullOrEmpty(key)) { return(null); } byte[] probed = null; using (var prov = new RNGEncryption(XORSecret, Mode)) { byte[] crypted = StripStorageInfos(key); if (crypted == null) { return(null); } probed = prov.GetDecryptedKey(crypted, lupn); if (probed == null) { return(null); } } if (probed.Length > MAX_PROBE_LEN) { byte[] buffer = new byte[MAX_PROBE_LEN]; Buffer.BlockCopy(probed, 0, buffer, 0, buffer.Length); return(buffer); } else { return(probed); } }