/// <summary> /// ValidateKey method implmentation /// </summary> public bool ValidateKey(string upn) { if (string.IsNullOrEmpty(upn)) { return(false); } string lupn = upn.ToLower(); string key = ReadKey(lupn); if (string.IsNullOrEmpty(key)) { return(false); } if (HasStorageInfos(key)) { byte[] crypted = StripStorageInfos(key); if (crypted == null) { return(false); } using (var prov = new AES256CNGEncryption(XORSecret)) { byte[] cleared = prov.GetDecryptedKey(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 } else { return(false); // Key corrupted } } } else { return(false); } }
/// <summary> /// ProbeKey method implmentation /// </summary> public 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; byte[] crypted = StripStorageInfos(key); if (crypted == null) { return(null); } using (var prov = new AES256CNGEncryption(XORSecret)) { 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, MAX_PROBE_LEN); return(buffer); } else { return(probed); } }