/// <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 CaesarEncryption1(XORSecret)) { crypted = prov.NewEncryptedKey(lupn); if (crypted == null) { return(null); } } string outkey = AddStorageInfos(crypted); return(KeysStorage.NewUserKey(lupn, outkey)); }
/// <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 CaesarEncryption1(XORSecret)) { byte[] crypted = StripStorageInfos(key); if (crypted == null) { return(null); } cleared = prov.GetDecryptedKey(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> /// ValidateKeyV1 method implmentation /// </summary> public override 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)) { using (var prov = new CaesarEncryption1(XORSecret)) { byte[] crypted = StripStorageInfos(key); if (crypted == null) { return(false); } byte[] cleared = prov.GetDecryptedKey(crypted, lupn); if (cleared == null) { return(false); // Key corrupted } else { return(true); } } } else { return(false); } }