/// <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)); } }