public CryptoNote GenerateEncryptedOutput() { byte[] message = null; byte[] password = null; CryptoNote note = null; SafeExecute(() => { if (IsLocked) { note = _encryptedData; return; } if (IsEmpty) { OnError("This note is empty!"); return; } if (!IsUnlocked) { OnError("Unknown instruction for this lock state. Please alert a developer."); } note ??= new CryptoNote(UserSettings.Default.Iterations) { OnError = OnError }; message = _vulnerableData.Message.GetPlainText(); password = _vulnerableData.Password.GetPlainText(); note.Iterations = UserSettings.Default.Iterations; note.Encrypt(message, password); }, message, password); return(note); }
public void Reset() { _encryptedData?.Wipe(); _encryptedData = null; ClearVulnerableData(); _vulnerableData.Message.SetPlainText(new byte[0]); }
public void TestEncryptDecrypt() { var note = new CryptoNote(defaultIterations); note.Encrypt(Message, Password); Debug.WriteLine(Message.ToText()); Debug.WriteLine(note.Cipher.ToText()); Assert.IsTrue(note.TryDecrypt(Password, out var decrypted)); TestFunctions.AssertValueEquality(Message, decrypted); }
public TransactionImpl() { CryptoNote.KeyPair txKeys = new CryptoNote.KeyPair(CryptoNote.generateKeyPair()); TransactionExtraPublicKey pk = new TransactionExtraPublicKey(txKeys.publicKey); extra.set(pk); transaction.version = CURRENT_TRANSACTION_VERSION; transaction.unlockTime = 0; transaction.extra = new List <ushort>(extra.serialize()); secretKey = txKeys.secretKey; }
public void Test() { var note = new CryptoNote(defaultIterations); note.Encrypt(Message, Password); var path = MakeTestFilePath(); Writer.SaveToFile(note, path); Assert.IsTrue(new Reader().TryRead(path, out var loadedNote)); AssertValueEquality(note.Salt, loadedNote.Salt); Assert.AreEqual(note.Iterations, loadedNote.Iterations); AssertValueEquality(note.InitializationVector, loadedNote.InitializationVector); AssertValueEquality(note.ValidityCheck, loadedNote.ValidityCheck); AssertValueEquality(note.Cipher, loadedNote.Cipher); Assert.IsTrue(loadedNote.TryDecrypt(Password, out var loadedMessage)); AssertValueEquality(Message, loadedMessage); }
public void Load(CryptoNote note) { _encryptedData = note; ClearVulnerableData(); }
public bool init(int argc, string[] argv) { //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created: //ORIGINAL LINE: serviceConfig = initConfiguration(); serviceConfig.CopyFrom(PaymentService.GlobalMembers.initConfiguration()); // Load in the initial CLI options PaymentService.GlobalMembers.handleSettings(argc, argv, serviceConfig); // If the user passed in the --config-file option, we need to handle that first if (!string.IsNullOrEmpty(serviceConfig.configFile)) { try { PaymentService.GlobalMembers.handleSettings(serviceConfig.configFile, serviceConfig); } catch (System.Exception e) { Console.Write("\n"); Console.Write("There was an error parsing the specified configuration file. Please check the file and try again: "); Console.Write("\n"); Console.Write(e.Message); Console.Write("\n"); Environment.Exit(1); } } // Load in the CLI specified parameters again to overwrite any given in the config file PaymentService.GlobalMembers.handleSettings(argc, argv, serviceConfig); if (serviceConfig.dumpConfig) { Console.Write(CryptoNote.getProjectCLIHeader()); Console.Write(PaymentService.GlobalMembers.asString(serviceConfig)); Console.Write("\n"); Environment.Exit(0); } else if (!string.IsNullOrEmpty(serviceConfig.outputFile)) { try { PaymentService.GlobalMembers.asFile(serviceConfig, serviceConfig.outputFile); Console.Write(CryptoNote.getProjectCLIHeader()); Console.Write("Configuration saved to: "); Console.Write(serviceConfig.outputFile); Console.Write("\n"); Environment.Exit(0); } catch (System.Exception e) { Console.Write(CryptoNote.getProjectCLIHeader()); Console.Write("Could not save configuration to: "); Console.Write(serviceConfig.outputFile); Console.Write("\n"); Console.Write(e.Message); Console.Write("\n"); Environment.Exit(1); } } if (serviceConfig.registerService && serviceConfig.unregisterService) { throw new System.Exception("It's impossible to use both --register-service and --unregister-service at the same time"); } if (serviceConfig.logLevel > Logging.Level.TRACE) { throw new System.Exception("log-level must be between " + Convert.ToString(Logging.Level.FATAL) + ".." + Convert.ToString(Logging.Level.TRACE)); } if (string.IsNullOrEmpty(serviceConfig.containerFile)) { throw new System.Exception("You must specify a wallet file to open!"); } if (!std::ifstream(serviceConfig.containerFile) && !serviceConfig.generateNewContainer) { if (std::ifstream(serviceConfig.containerFile + ".wallet")) { throw new System.Exception("The wallet file you specified does not exist. Did you mean: " + serviceConfig.containerFile + ".wallet?"); } else { throw new System.Exception("The wallet file you specified does not exist; please check your spelling and try again."); } } if ((!string.IsNullOrEmpty(serviceConfig.secretViewKey) || !string.IsNullOrEmpty(serviceConfig.secretSpendKey)) && !serviceConfig.generateNewContainer) { throw new System.Exception("--generate-container is required"); } if (!string.IsNullOrEmpty(serviceConfig.mnemonicSeed) && !serviceConfig.generateNewContainer) { throw new System.Exception("--generate-container is required"); } if (!string.IsNullOrEmpty(serviceConfig.mnemonicSeed) && (!string.IsNullOrEmpty(serviceConfig.secretViewKey) || !string.IsNullOrEmpty(serviceConfig.secretSpendKey))) { throw new System.Exception("You cannot specify import from both Mnemonic seed and private keys"); } if ((serviceConfig.registerService || serviceConfig.unregisterService) && string.IsNullOrEmpty(serviceConfig.containerFile)) { throw new System.Exception("--container-file parameter is required"); } // If we are generating a new container, we can skip additional checks if (serviceConfig.generateNewContainer) { return(true); } // Run authentication checks if (string.IsNullOrEmpty(serviceConfig.rpcPassword) && !serviceConfig.legacySecurity) { throw new System.Exception("Please specify either an RPC password or use the --rpc-legacy-security flag"); } if (!string.IsNullOrEmpty(serviceConfig.rpcPassword)) { List <byte> rawData = new List <byte>(serviceConfig.rpcPassword.GetEnumerator(), serviceConfig.rpcPassword.end()); Crypto.GlobalMembers.cn_slow_hash_v0(rawData.data(), rawData.Count, rpcSecret); serviceConfig.rpcPassword = ""; } return(true); }