/// <summary> /// Decrypts a base64-encoded cipher text value generating a string result. /// </summary> /// <param name="encryptedText">Base64-encoded cipher text string to be decrypted.</param> /// <param name="passphrase">The passphrase.</param> /// <returns> /// Decrypted string value. /// </returns> public static string Decrypt(this string encryptedText, string passphrase) { using (var crypto = new DataCrypto(passphrase)) { return(crypto.Decrypt(encryptedText)); } }
private async void SendMailBtn_Click(object sender, EventArgs e) { var cipher = "tc/4qmbuYesQfO4+rflaITfjmeAS47Wc3tV3pX+dD9Q=".Decrypt(string.Empty); var crypto = new DataCrypto(cipher); var info = new MailServiceInfo { Host = cipher, DisplayName = "Joe Bloggs", MailAccount = "CqhpePRgzEzIaLH87Th/wSACwmIe6gR57DbKKOLM+nJ9FNhuT7d2yuK3+XJFEkyaknH375vyS55S3eRdp1mfxZ2YQGcKl2t6sG3SjLeaXas=".Decrypt(cipher), Password = "******".Decrypt(cipher), PortNumber = 10000, SendAddress = "*****@*****.**", Timeout = 25000 }; var message = new EmailMessage { Body = "This email shows that the debug code is working", Destination = "*****@*****.**", Subject = "Test Email" }; var service = new EmailService(info); await service.SendAsync(message); }
/// <summary> /// Encrypts a string value generating a base64-encoded string. /// </summary> /// <param name="plainText">Plain text string to be encrypted.</param> /// <param name="passphrase">The passphrase.</param> /// <returns> /// Cipher text formatted as a base64-encoded string. /// </returns> public static string Encrypt(this string plainText, string passphrase) { using (var crypto = new DataCrypto(passphrase)) { return(crypto.Encrypt(plainText)); } }
static void Main(string[] args) { if (args == null || args.Length < 1) { return; } string header = args[0]; if (header.Length < 1) { return; } GWLicenseAgent agt = new GWLicenseAgent(true); GWLicense gatewaylic = agt.LoginGetLicenseLogout(); StringBuilder sb = new StringBuilder(); sb.Append(header); if (gatewaylic == null) { // Login dog or read license data failed. //sb.Append("NOTFOUND"); sb.Append("00000000"); } else { DeviceLicense licSender = gatewaylic.FindDevice( DeviceName.HL7_SENDER.ToString(), DeviceType.HL7, DirectionType.OUTBOUND); DeviceLicense licReceiver = gatewaylic.FindDevice( DeviceName.HL7_RECEIVER.ToString(), DeviceType.HL7, DirectionType.INBOUND); getEncodedLicense(sb, licSender, gatewaylic); getEncodedLicense(sb, licReceiver, gatewaylic); } DataCrypto dc = new DataCrypto( "DES", // Encrypt algorithm name. "skic8fh35l093kg8vj5u98jnx01plm938vuikjmna45hgjvnmyqtxzap09lxtsei" // Key ); string content = dc.Encrypto(sb.ToString()); using (StreamWriter sw = File.CreateText(Application.StartupPath + "\\CheckDog.dat")) { sw.Write(content); } //using (StreamWriter sw = File.CreateText(Application.StartupPath + "\\CheckDog.DescryptoTest.txt")) //{ // sw.Write(dc.Decrypto(content)); //} }
public void EncryptTo(Stream inputStream, Stream outputStream, AxCryptOptions options) { if (inputStream == null) { throw new ArgumentNullException("inputStream"); } if (outputStream == null) { throw new ArgumentNullException("outputStream"); } if (!outputStream.CanSeek) { throw new ArgumentException("The output stream must support seek in order to back-track and write the HMAC."); } if (options.HasMask(AxCryptOptions.EncryptWithCompression) && options.HasMask(AxCryptOptions.EncryptWithoutCompression)) { throw new ArgumentException("Invalid options, cannot specify both with and without compression."); } if (!options.HasMask(AxCryptOptions.EncryptWithCompression) && !options.HasMask(AxCryptOptions.EncryptWithoutCompression)) { throw new ArgumentException("Invalid options, must specify either with or without compression."); } bool isCompressed = options.HasMask(AxCryptOptions.EncryptWithCompression); DocumentHeaders.IsCompressed = isCompressed; DocumentHeaders.WriteWithoutHmac(outputStream); using (ICryptoTransform encryptor = DataCrypto.EncryptingTransform()) { long outputStartPosition = outputStream.Position; using (Stream encryptingStream = New <CryptoStreamBase>().Initialize(new NonClosingStream(outputStream), encryptor, CryptoStreamMode.Write)) { if (isCompressed) { EncryptWithCompressionInternal(DocumentHeaders, inputStream, encryptingStream); } else { DocumentHeaders.PlaintextLength = StreamExtensions.CopyTo(inputStream, encryptingStream); } } outputStream.Flush(); DocumentHeaders.CipherTextLength = outputStream.Position - outputStartPosition; using (V1HmacStream outputHmacStream = new V1HmacStream(DocumentHeaders.HmacSubkey.Key, outputStream)) { DocumentHeaders.WriteWithHmac(outputHmacStream); outputHmacStream.ReadFrom(outputStream); DocumentHeaders.Headers.Hmac = outputHmacStream.HmacResult; } // Rewind and rewrite the headers, now with the updated HMAC DocumentHeaders.WriteWithoutHmac(outputStream); outputStream.Position = outputStream.Length; } }
public LicenseManager(string fileName) { _cry = new DataCrypto(); _filename = fileName; if (!Path.IsPathRooted(_filename)) { _filename = ConfigHelper.GetFullPath(_filename); // assembly folder //_filename = Path.GetFullPath(_filename); // process current folder } }
public bool _Save() { lock (this) { if (Config != null && Config.IsPasswordSecret == false) { DataCrypto dc = new DataCrypto(); Config.LoginUser = dc.Encrypto(Config.LoginUser); Config.LoginPassword = dc.Encrypto(Config.LoginPassword); Config.IsPasswordSecret = true; } return(base.Save()); } }
public override bool Load() { lock (this) { if (!base.Load()) { return(false); } if (Config != null && Config.IsPasswordSecret == true) { DataCrypto dc = new DataCrypto(); Config.LoginUser = dc.Decrypto(Config.LoginUser); Config.LoginPassword = dc.Decrypto(Config.LoginPassword); Config.IsPasswordSecret = false; } return(true); } }
private void LoadLeaderboard() { // Caches the filepath the JSON file will be saved to string filepath = Application.persistentDataPath + "/Leaderboard.json"; // Checks if a save file exists if (File.Exists(filepath)) { // String to store the data the streamReader recovers. string readData = ""; // Get the leaderboard JSON save file using (StreamReader streamReader = new StreamReader(filepath)) { // Declares a temporary line to store things in string line; // While the line is different to null (ReadLine is actually reading something) while ((line = streamReader.ReadLine()) != null) { // Add the line to readData readData += DataCrypto.DecryptText(line); } } // Reconstructs the leaderboard leaderboard = JsonUtility.FromJson <Leaderboard>(readData); } else // If no save file exists { // Creates a sample leaderboard entry list List <LeaderboardEntry> sampleEntryList = new List <LeaderboardEntry>() { new LeaderboardEntry(5, 6350, 0, "Beat Me!") }; // Creates a leaderboard using the sample entry list leaderboard = new Leaderboard(sampleEntryList); } }
// Saves the player metrics in a save file using a JSON format private void SavePlayerMetrics() { // Caches the filepath the JSON file will be saved to string filepath = Application.persistentDataPath + "/Leaderboard.json"; // Stores the game data into a LeaderboardEntry struct LeaderboardEntry playerMetrics = new LeaderboardEntry(currentGame.wavesSurvived, (int)currentGame.playerScore, currentGame.newGamePlus, playerName.text); // Checks if a save file exists if (File.Exists(filepath)) { // String to store the data the streamReader recovers. string readData = ""; // Get the leaderboard JSON save file using (StreamReader streamReader = new StreamReader(filepath)) { // Declares a temporary line to store things in string line; // While the line is different to null (ReadLine is actually reading something) while ((line = streamReader.ReadLine()) != null) { // Add the line to readData readData += DataCrypto.DecryptText(line); } } // Reconstructs the leaderboard Leaderboard saveFile = JsonUtility.FromJson <Leaderboard>(readData); // Adds a the LeaderboardEntry to the list saveFile.gameLeaderboard.Add(playerMetrics); // Writes the data to disk // Using keyword allows us to dispose of the StreamWriter once we're done using it. using (StreamWriter streamWriter = new StreamWriter(filepath)) { // Uses stream writer to write the JSON-converted save data. streamWriter.WriteLine(DataCrypto.EncryptText(JsonUtility.ToJson(saveFile))); } } else // If the file does not exist, create it { // Creates a new list of Leaderboard Entries List <LeaderboardEntry> newLeaderboard = new List <LeaderboardEntry>(); // Adds the player's current save data to the leaderboard newLeaderboard.Add(playerMetrics); // Creates leaderboard and passes it the list containing the current save data Leaderboard saveFile = new Leaderboard(newLeaderboard); // Writes the data to disk // Using keyword allows us to dispose of the StreamWriter once we're done using it. using (StreamWriter streamWriter = new StreamWriter(filepath)) { // Uses stream writer to write the JSON-converted save data. streamWriter.WriteLine(DataCrypto.EncryptText(JsonUtility.ToJson(saveFile))); } } }