public async void Import() { //BIP 39 var sentence = string.Join(" ", faucet.mnemonic); (byte[] publicKey, byte[] privateKey) = CryptoServices.ImportBIP39(sentence, faucet.email, faucet.password); var keypair = new KeyPair ( new PublicKey(publicKey), new PrivateKey(privateKey, PIN) ); // Import Identity var identity = Engine.FindIdentity(keypair.PublicID); if (identity == null) { identity = await Engine.ImportIdentity( IdentityType.Light.Stereotype, Name, keypair); } identity.Unlock(PIN); Main.CurrentIdentity = (IdentityVM)identity; WhenComplete.SetComplete(); // Activate await Engine.ActivateIdentity(identity, faucet.secret, faucet.ModelAmount); }
public void SelectGuess() { words.Add(BestGuess); FirePropertyChanged(nameof(Sentence)); if (IsSentenceComplete) { // Check BIP39 validity if (CryptoServices.IsValidBIP39(Sentence)) { FirePropertyChanged(nameof(IsSentenceComplete)); } else { IsSentenceInvalid = true; FirePropertyChanged(nameof(IsSentenceInvalid)); FirePropertyChanged(nameof(IsSentenceValid)); } } else { // Clear for next word CurrentWord = string.Empty; FirePropertyChanged(nameof(WordTip)); } }
public void RegisterTest() { //Arrange string myName = "testuser"; SecureString myPass = new SecureString(); myPass.AppendChar('P'); myPass.AppendChar('@'); myPass.AppendChar('s'); myPass.AppendChar('$'); myPass.AppendChar('w'); myPass.AppendChar('0'); myPass.AppendChar('r'); myPass.AppendChar('D'); //Act var user = CryptoServices.Register(myName, myPass, new string[] { "Cute_Cat" }); //Assert bool CorrectLogin = CryptoServices.CheckPassword("testuser", "P@s$w0rD"); Assert.IsTrue(CorrectLogin); bool WrongUser = CryptoServices.CheckPassword("NotMomi", "P@s$w0rD"); Assert.IsFalse(WrongUser); bool WrongLogin = CryptoServices.CheckPassword("testuser", "88881234"); Assert.IsFalse(WrongLogin); }
static RequestObjectManager() { LockObject = new Object(); LastGCCollection = DateTime.Now; CollectWindow = TimeSpan.FromMinutes(5); ThreadDataName = CryptoServices.RandomIdToUInt32().ToString(); }
static void Main(string[] args) { Console.WriteLine("----==== Norn Wallet ====----"); Console.WriteLine(); Console.WriteLine("Norn Wallet created by Norn Community: https://t.me/invest_flood"); Console.WriteLine(); Console.WriteLine("Choose action:"); Console.WriteLine("1 - Import mnemonic"); Console.WriteLine("2 - Import private key"); Console.WriteLine("Esc - exit"); var key = Console.ReadKey().Key; Console.WriteLine(); switch (key) { case ConsoleKey.D1: ImportSeed(); break; case ConsoleKey.D2: ImportSk(); break; default: return; } Console.WriteLine(); Console.Write("Enter current block hash: "); hash = Console.ReadLine(); Console.Write("Enter account counter: "); counter = Console.ReadLine(); int cnt = int.Parse(counter); Console.Write("Enter destination address: "); string to = Console.ReadLine(); Console.Write("Enter amount: "); string amount = Console.ReadLine(); Console.Write("Enter fee: "); string fee = Console.ReadLine(); var hashBytesString = CryptoServices.DecodePrefixed(HashType.Block, hash).ToHexString(); var toBytesString = CryptoServices.DecodePrefixed(HashType.PublicKeyHash, to).ToHexString(); Console.WriteLine(); cnt++; string transferOp = hashBytesString + "080000" + CryptoServices.DecodePrefixed(HashType.PublicKeyHash, tz1).ToHexString() + int.Parse(fee).EncodeInt32() + cnt.EncodeInt32() + 400.EncodeInt32() + 0.EncodeInt32() + ((int)(decimal.Parse(amount, CultureInfo.InvariantCulture) * 1000000)).EncodeInt32() + "01" + toBytesString + "0000"; var opBytes = ("03" + transferOp).HexToByteArray(); var hashedData = CryptoServices.Hash(opBytes, 32); var bsign = CryptoServices.CreateSignature(privateKey, hashedData); var inject = transferOp + bsign.ToHexString(); Console.WriteLine("Operation hex:"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(inject); Console.ForegroundColor = ConsoleColor.Gray; }
private void ParseReveal() { var header = ParseHeader(); var what = TakeOne(); var publicKey = CryptoServices.EncodePrefixed(HashType.Public, Take(32)); }
public Task <bool> Sign(string identityID, byte[] data, out byte[] signature) { Assert.AreEqual(this.identityID, identityID); signature = CryptoServices.CreateSignature(privateKey, data); return(Task.FromResult(true)); }
public Task Initialize() { CryptoServices.CreateKeyPair(out publicKey, out privateKey); identityID = CryptoServices.CreatePrefixedHash(HashType.PublicKeyHash, publicKey); return(Task.CompletedTask); }
public ListenerRouter() { Disposed = false; ListenerRequest = new MessageRequest() { SessionId = CryptoServices.RandomIdToUInt64() }; LastUnsuccessfulConnection = DateTime.MinValue; LastUnsuccessfulWaitTime = 5; // 5 seconds }
//ideographic space used by japanese language #endregion Public Constants and Enums #region Constructors /// <summary> /// Constructor to build a BIP39 object from scratch given an entropy size and an optional passphrase. Language is optional and will default to English /// </summary> /// <param name="entropySize">The size in bits of the entropy to be created</param> /// <param name="passphrase">The optional passphrase. Please ensure NFKD Normalized, Empty string will be used if not provided as per spec</param> /// <param name="language">The optional language. If no language is provided English will be used</param> public BIP39(int entropySize = cMinimumEntropyBits, string passphrase = cEmptyString, Language language = Language.English) { //check that ENT size is a multiple of 32 and at least minimun entropy size to stop silly people using tiny entropy, oh also making sure entropy size doesn't exceed our checksum bits available if (entropySize % cEntropyMultiple != 0 || entropySize < cMinimumEntropyBits || entropySize > cMaximumEntropyBits) { throw (new Exception("entropy size must be a multiple of " + cEntropyMultiple + " (divisible by " + cEntropyMultiple + " with no remainder) and must be greater than " + (cMinimumEntropyBits - 1) + " and less than " + (cMaximumEntropyBits + 1))); } _entropyBytes = CryptoServices.CreateRandomBytes(entropySize / cBitsInByte); //crypto random entropy of the specified size Init(passphrase, language); }
internal static void ApplySignature(ProtectedTask task, byte[] data, byte[] signature) { task.Signature = CryptoServices.EncodePrefixed(HashType.Signature, signature); using (var buffer = new MemoryStream()) { buffer.Write(data, 0, data.Length); buffer.Write(signature, 0, signature.Length); task.SignedOperation = buffer.ToArray().ToHexString(); } }
private async void button2_Click(object sender, EventArgs e) { if (fallos == 3) { MessageBox.Show("Demasiados intentos...\nCerrando App"); this.Close(); } if (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text)) { MessageBox.Show("Favor de llenar los datos requeridos"); txtUsername.Focus(); return; } using (var db = new RRHHContext()) { string user = txtUsername.Text.Trim().ToLower(); string pass = txtPassword.Text.Trim(); var u = await db.Credenciales.FirstOrDefaultAsync(x => x.UserName.ToLower().Equals(user)); if (u == null) { MessageBox.Show("Usuario no encontrado."); Clear(); return; } var encrypted = CryptoServices.Encrypt(pass); if (!u.Password.Equals(encrypted)) { MessageBox.Show("Contraseña Incorrecta"); txtPassword.Clear(); txtPassword.Focus(); fallos += 1; return; } MessageBox.Show("Contraseña Correcta"); fallos = 0; SimpleModels.EmpleadoDataModel userdata = new SimpleModels.EmpleadoDataModel() { Id = u.EmpleadoId, Nombre = u.DatosEmpleado.Nombre, Cedula = u.DatosEmpleado.Cedula, UserName = u.UserName }; var mdi = new MDIs.MDI_User(db, userdata); this.Hide(); mdi.ShowDialog(); this.Show(); Clear(); } }
public bool CanUnlockWith(Passphrase passphrase) { try { var privateData = PrivateKey.AccessData(passphrase); return(CryptoServices.IsKeyMatch(PublicKey.Data, privateData)); } catch { return(false); } }
public ParsedOperation(byte[] operationData) { this.operationData = operationData; // Branch Branch = CryptoServices.EncodePrefixed(HashType.Block, Take(32)); // Items while (!EndOfData) { ParseItem(); } }
public T GetRequestObject(CreateRequestObjectHandler <T> createRequestObject, out Boolean bNew) { GCCollection(); RequestObjectExtension requestExtention = null; bNew = false; if (OperationContext.Current != null) { requestExtention = OperationContext.Current.Extensions.Find <RequestObjectExtension>(); if (createRequestObject != null && requestExtention == null) { bNew = true; requestExtention = new RequestObjectExtension(CryptoServices.RandomIdToUInt32()); requestExtention.RequestObject = CreateAndAttachRequestObject(createRequestObject, requestExtention.Key); OperationContext.Current.Extensions.Add(requestExtention); } } else // we are bound to thread affinity { requestExtention = ThreadRequestionExtension; if (createRequestObject != null && (requestExtention == null || (Thread.CurrentThread.IsThreadPoolThread && CallContext.GetData(ThreadDataName) == null))) { if (requestExtention != null) { requestExtention.Dispose(); ThreadRequestionExtension = null; } var threadId = (UInt32)Thread.CurrentThread.ManagedThreadId + ReflectInsightService.SessionId; if (Thread.CurrentThread.IsThreadPoolThread) { CallContext.SetData(ThreadDataName, new Object()); } bNew = true; requestExtention = new RequestObjectExtension(threadId); requestExtention.RequestObject = CreateAndAttachRequestObject(createRequestObject, requestExtention.Key); // bind the request to the thread ThreadRequestionExtension = requestExtention; } } return(requestExtention != null ? requestExtention.RequestObject : default(T)); }
private static void ImportSk() { Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("Import private key"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Enter encoded private key: "); edsk = Console.ReadLine(); var keys = CryptoServices.ImportEd25519(edsk); publicKey = keys.Item1; privateKey = keys.Item2; tz1 = CryptoServices.CreatePrefixedHash(HashType.PublicKeyHash, publicKey); edsk = CryptoServices.EncodePrefixed(HashType.Private, privateKey); }
private static RedmineManager CreateRedmineManager(IssueTrackerConfiguration config) { string host = config.GetValue(CSRedmineExtension.HOST_KEY); string apikey = config.GetValue(CSRedmineExtension.APIKEY_KEY); if (apikey == null || apikey == String.Empty) { string user = config.GetValue(CSRedmineExtension.USER_KEY); // config.User; string password = CryptoServices.GetDecryptedPassword(config.GetValue(CSRedmineExtension.PASSWORD_KEY)); return(new RedmineManager(host, user, password)); } return(new RedmineManager(host, apikey)); }
public string GetDecryptedPassword() { if (Config == null) { throw new ApplicationException("The configuration has not yet been initialized!"); } if (string.IsNullOrEmpty(Password)) { throw new ApplicationException("Password value can not be empty!"); } var decryptedPassword = CryptoServices.GetDecryptedPassword(Password); return(decryptedPassword); }
private string ParseAccountID() { switch (TakeOne()) { case 0: // Identity return(ParseIdentityID()); case 1: // Account var data = Take(20); TakeOne(); // Padding return(CryptoServices.EncodePrefixed(HashType.Account, data)); default: throw new NotImplementedException(); } }
private static void ImportSeed() { Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("Import mnemonic"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Enter words: "); mnemonic = Console.ReadLine(); Console.Write("Enter password or press Enter: "); string pass = Console.ReadLine(); var bip = new BIP39(mnemonic, pass); var seed = new ArraySegment <byte>(bip.SeedBytes, 0, Ed25519.PrivateKeySeedSizeInBytes); Ed25519.KeyPairFromSeed(out publicKey, out privateKey, seed.ToArray()); tz1 = CryptoServices.CreatePrefixedHash(HashType.PublicKeyHash, publicKey); edsk = CryptoServices.EncodePrefixed(HashType.Private, privateKey); }
public bool IsValidAccountID(string accountID) { if (string.IsNullOrWhiteSpace(accountID)) { return(false); } try { CryptoServices.DecodePrefixed(HashType.PublicKeyHash, accountID); return(true); } catch (Exception) { return(false); } }
public ActionResult <string> AddFifty([FromQuery] string encryptedInteger, string encryptedSymKey, string encryptedIV) { try { var symKey = DecryptHex(encryptedSymKey); var IV = DecryptHex(encryptedIV); var integerByteForm = DecryptHex(encryptedInteger); var integerString = Encoding.Default.GetString(integerByteForm); var integer = Convert.ToInt32(integerString); var returnInt = integer + 50; var returnEncrypted = CryptoServices.AesEncrypt(returnInt.ToString(), symKey, IV); var returnString = BitConverter.ToString(returnEncrypted); return(Ok(returnString)); } catch { return(BadRequest("Bad Request")); }
public Task <bool> Sign(string identityID, byte[] data, out byte[] signature) { signature = null; // Find identity var identity = Find(identityID); if (identity != null) { if (identity.IsUnlocked) { // Sign signature = CryptoServices.CreateSignature(identity.PrivateKeyData, data); return(Task.FromResult(true)); } } return(Task.FromResult(false)); }
public void LogIn_Action() { CurrentUser = CryptoServices.LogIn(UserName, Password); if (CurrentUser == null) { MessageBox.Show("Login Not successful"); Password = null; } else { #if DEBUG Trace.WriteLine($"[LoginViewModel]: Welcome, {CurrentUser.Identity.Name}, Is Authenticated: {CurrentUser.Identity.IsAuthenticated}"); Trace.Flush(); #endif Window wkspace = new WorkspaceWindow(); wkspace.Show(); Application.Current.MainWindow = wkspace; Application.Current.Windows[0].Close(); } }
private string ParseIdentityID() { HashType hashType; switch (TakeOne()) { case 0: hashType = HashType.PublicKeyHash; break; case 1: hashType = HashType.PublicKeyHash2; break; case 2: hashType = HashType.PublicKeyHash3; break; default: throw new NotImplementedException(); } return(CryptoServices.EncodePrefixed(hashType, Take(20))); }
static byte[] DecryptHex(string hex) { var byteform = CryptoServices.HexToByte(hex); return(CryptoServices.RSA.Decrypt(byteform, true)); }
public static string Encrypt(string plaintext) { return(CryptoServices.Encrypt(plaintext)); }
EncryptionConfigurationDialogData BuildEncryptionConfigurationData() { return(new EncryptionConfigurationDialogData( CryptoServices.GetEncryptedPassword(mPassword.Trim()))); }
public ActionResult <string> GetSha256([FromQuery] string message) { return(message is null ? BadRequest("Bad Request") : (ActionResult <string>)Ok(CryptoServices.Hasher(message, new SHA256Managed()))); }
public static string Decrypt(string ciphertext) { return(CryptoServices.Decrypt(ciphertext)); }