public void HashedUserTest() { IOpenPgpKeySearch pgpKeys = new OpenPgpKeySearch(); var hu = pgpKeys.GetHashedUserId("me"); Assert.Equal("s8y7oh5xrdpu9psba3i5ntk64ohouhga", hu); }
private static WkdSavedKeys LoadPublicKeys(IEnumerable <PgpPublicKey> publicKeys, OpenPgpKeyManagement?keyManagement = null) { var context = new WkdSavedKeys(); var keySearch = new OpenPgpKeySearch(); if (keyManagement == null) { keyManagement = new OpenPgpKeyManagement(); } foreach (var key in publicKeys) { foreach (string userId in key.GetUserIds()) { MailAddress mailAddress; try { mailAddress = new MailAddress(userId); } catch (FormatException) { // UserId is not a mail adress, we don't save it continue; } var host = mailAddress.Host; Dictionary <string, string> hostDic; if (!context.PublicKeys.TryGetValue(host, out hostDic)) { hostDic = new Dictionary <string, string>(); context.PublicKeys.Add(host, hostDic); } var user = keySearch.GetHashedUserId(mailAddress.User); if (hostDic.ContainsKey(user)) { // we already have a public key for this e-mail address continue; } var keyString = keyManagement.Export(key); hostDic.Add(user, keyString); } } return(context); }