public void GenerationTest() { var hash = RawInput.ComputeHash(); var dateString = DateNow.ToString("ddMMyyyy"); var hashAndProductAndDate = InsertProductAndDate(NUnit3Product + dateString, Nunit3PosArray, hash); var guidSalt = FileHelper.GetGuid(); var elb = ReversibleEncryption.Encrypt(PublicKey, hashAndProductAndDate + guidSalt); var writableLicence = elb.AsHex(); //Start undoing what we did var elbAfterAsHexAsBytes = writableLicence.AsBytes(); Assert.That(StructuralComparisons.StructuralEqualityComparer.Equals(elb, elbAfterAsHexAsBytes)); var decryptedLicenceBytes = ReversibleEncryption.Decrypt(PublicKey, elbAfterAsHexAsBytes); Assert.That(decryptedLicenceBytes.Equals(hashAndProductAndDate + guidSalt)); var restoredHashAndProductAndDate = decryptedLicenceBytes.Remove(decryptedLicenceBytes.Length - 36); Assert.That(restoredHashAndProductAndDate.Equals(hashAndProductAndDate)); var restoredHash = ExtractProductAndDate(Nunit3PosArray, restoredHashAndProductAndDate); Assert.That(restoredHash[1].Equals(hash)); Assert.That(restoredHash[0].Equals(NUnit3Product + dateString)); }
/// <summary> /// Gets the password associated with the PDFDocument. Returns null if there is no associated password. /// </summary> /// <param name="pdf_document"></param> /// <returns></returns> public string GetPassword(PDFDocument pdf_document) { if (Passwords.ContainsKey(pdf_document.Fingerprint)) { ReversibleEncryption re = new ReversibleEncryption(); return(re.DecryptString(Passwords[pdf_document.Fingerprint])); } else { return(null); } }
public void LicenceStringIsValidContent() { const string licence = "0C01614ADE00BC13BEFF530C5D93E1B10CD917B35FE98A94BA7738159BEC679ACF0C5C68D5C7F1AB91AA85D5E8CA37345B291547E76A5147D615EF23C25422D269F8A202F7EBE394D83292F764CFA83C7D994D02DA6A278BE7F2A7A869947D99F2B32A6E4FC3A8713E755339E8DE357FB86E6883645BA37DB8E16170B4B24308"; var writtenActivationKeyGS = ReversibleEncryption.Decrypt(PublicKey, licence.AsSauceryBytes()); var writtenGS = writtenActivationKeyGS.ExtractGuidSalt(); const string expectedGuidSalt = "d010fe00-bd6a-4c94-85ff-da9ba45b769d"; var sauceryActivationKey = writtenActivationKeyGS.Remove(writtenActivationKeyGS.Length - 36); Assert.That(Hasher.ProductAndDateIsValid(sauceryActivationKey) && StringComparer.OrdinalIgnoreCase.Compare(expectedGuidSalt, writtenGS) == 0); }
/// <summary> /// Gets the password associated with the PDFDocument. Returns null if there is no associated password. /// </summary> /// <param name="pdf_document"></param> /// <returns></returns> public string GetPassword(PDFDocument_ThreadUnsafe pdf_document) { string fingerprint = pdf_document.Fingerprint; if (Passwords.ContainsKey(fingerprint)) { ReversibleEncryption re = new ReversibleEncryption(); return(re.DecryptString(Passwords[fingerprint])); } else { return(null); } }
public void AcceptanceTest() { const string rawInput = Name + Company + Email; var dateNowString = DateTime.Now.ToString("ddMMyyyy"); var productAndDate = NUnit3Product + dateNowString; var activationKey = InsertProductAndDate(productAndDate, Nunit3PosArray, rawInput.ComputeHash()); const string myGuid = "d010fe00-bd6a-4c94-85ff-da9ba45b769d"; Assert.That(Hasher.VerifyIdentity(rawInput, activationKey)); var encryptedLicenceBytes = ReversibleEncryption.Encrypt(PublicKey, activationKey + myGuid); var writableLicence = encryptedLicenceBytes.AsHex(); Assert.That(FileHelper.LicenceStringIsValidContent(writableLicence)); }
// ------------------------------------------------------------------------------------------------------------ /// <summary> /// Associates a password with the PDFDocument. /// Pass in numm or empty string to clear the password. /// </summary> /// <param name="pdf_document"></param> /// <param name="password"></param> public void AddPassword(PDFDocument pdf_document, string password) { if (null == pdf_document) { Logging.Warn("Can't associate a password with a null PDFDocument."); } if (String.IsNullOrEmpty(password)) { RemovePassword(pdf_document); } else { ReversibleEncryption re = new ReversibleEncryption(); Passwords[pdf_document.Fingerprint] = re.EncryptString(password); WritePasswordFile(Filename_Store, Passwords); } }