public GenerateKeysCommand() { Name = "generate-key"; Description = "Generate an RSA private and public key for usage as Licence generator"; this.HelpOption(); UsePagerForHelpText = false; OnExecute(() => { var keyGen = new RsaKeyPairGenerator(); keyGen.Init(new KeyGenerationParameters(new SecureRandom(), 4096)); var keyPair = keyGen.GenerateKeyPair(); PrivateKeyInfo pkInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(keyPair.Private); String privateKey = Convert.ToBase64String(pkInfo.GetDerEncoded()); var textWriter = new StreamWriter(new FileStream("./keys/private.pem", FileMode.Create)); var pemWriter = new PemWriter(textWriter); pemWriter.WriteObject(keyPair.Private); pemWriter.Writer.Flush(); textWriter.Close(); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public); String publicKey = Convert.ToBase64String(info.GetDerEncoded()); var text2Writer = new StreamWriter(new FileStream("./keys/public.pub", FileMode.Create)); var pubWriter = new PemWriter(text2Writer); pubWriter.WriteObject(keyPair.Public); pubWriter.Writer.Flush(); text2Writer.Close(); Console.WriteLine("Public and private key generated successfully."); return(1); }); }
/// <summary> /// Constructor to be used to factor a new RSA key pair. /// <param name="passphrase">Client secret password used to encrypt the /// private key.</param> /// <param name="overwriteExisting">Flag allowing or denying to replace /// an existing PEM file.</param> /// </summary> public RsaKeyPair(string passphrase, bool overwriteExisting) { if (!IsConfigured) { Configure(); } _overwriteExisting = overwriteExisting; AsymmetricCipherKeyPair keyPair = FactorKeyPair(); PrivateKeyInfo pkInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(keyPair.Private); _privateKey = new EncryptionKey(KeyType.RSAPrivate, Convert.ToBase64String(pkInfo.GetDerEncoded()).ToSecureString(), EncryptionParameters.KEY_GENERATION_START); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public); _publicKey = new EncryptionKey(KeyType.RSAPublic, Convert.ToBase64String(info.GetDerEncoded()).ToSecureString(), EncryptionParameters.KEY_GENERATION_START); //// Encrypt private key info for later to be stored with the SavePrivateKeyAsPemFile method _pwd = passphrase.ToSecureString(); _privateKeyInfo = PrivateKeyFactory.CreateKey(pkInfo); keyPair = null; pkInfo = null; info = null; GC.Collect(); }
public void Generate() { var keyPair = GenerateKeyPair(); PrivateKeyInfo privateKeyInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(keyPair.Private); PrivateKey = privateKeyInfo.GetDerEncoded(); SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public); PublicKey = publicKeyInfo.GetDerEncoded(); }
public AsymmetricCipherKeyPair GenerateKey() { RsaKeyPairGenerator kpGenerator = new RsaKeyPairGenerator(); kpGenerator.Init(new KeyGenerationParameters(new SecureRandom(), 512)); var keyPair = kpGenerator.GenerateKeyPair(); //PrivateKeyInfo pkInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(keyPair.Private); //PrivateKey = Convert.ToBase64String(pkInfo.GetDerEncoded()); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public); PublicKey = Convert.ToBase64String(info.GetDerEncoded()); return(keyPair); }
public ProofOfPossessionSigningKeyBuilder setPublicKeyMac(PKMacBuilder generator, char[] password) { IMacFactory fact = generator.Build(password); IStreamCalculator calc = fact.CreateCalculator(); byte[] d = _pubKeyInfo.GetDerEncoded(); calc.Stream.Write(d, 0, d.Length); calc.Stream.Flush(); calc.Stream.Close(); this._publicKeyMAC = new PKMacValue( (AlgorithmIdentifier)fact.AlgorithmDetails, new DerBitString(((IBlockResult)calc.GetResult()).Collect())); return(this); }
public ProofOfPossessionSigningKeyBuilder SetPublicKeyMac(PKMacBuilder generator, char[] password) { IMacFactory fact = generator.Build(password); IStreamCalculator calc = fact.CreateCalculator(); byte[] d = _pubKeyInfo.GetDerEncoded(); calc.Stream.Write(d, 0, d.Length); calc.Stream.Flush(); BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(calc.Stream); this._publicKeyMAC = new PKMacValue( (AlgorithmIdentifier)fact.AlgorithmDetails, new DerBitString(((IBlockResult)calc.GetResult()).Collect())); return(this); }
public KriptalKeyPair CreateKeyPair() { var kpgen = new RsaKeyPairGenerator(); kpgen.Init(new KeyGenerationParameters(new SecureRandom(), 2048)); var keyPair = kpgen.GenerateKeyPair(); PrivateKeyInfo pkInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(keyPair.Private); var privateKey = Convert.ToBase64String(pkInfo.GetDerEncoded()); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public); var publicKey = Convert.ToBase64String(info.GetDerEncoded()); return(new KriptalKeyPair { PrivateKey = privateKey, PublicKey = publicKey }); }
public static string GetHeaderValueForCert(X509Certificate2 certificate) { X509Certificate bouncyCert = DotNetUtilities.FromX509Certificate(certificate); AsymmetricKeyParameter publicKey = bouncyCert.GetPublicKey(); SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(publicKey); byte[] encodedDerValue = publicKeyInfo.GetDerEncoded(); byte[] hash = null; using (SHA256Managed sha256 = new SHA256Managed()) { hash = sha256.ComputeHash(encodedDerValue); } byte[] subValue = hash.Take(30).ToArray(); string base32EncodedSub = Base32.Encode(subValue); return(FormatKid(base32EncodedSub)); }
public Crypto() { int strength = 512; var kpgen = new RsaKeyPairGenerator(); kpgen.Init(new KeyGenerationParameters(new SecureRandom(new CryptoApiRandomGenerator()), strength)); // on stock la clé privé sous forme AsymmetricCipherKeyPair lesdeuxcles = kpgen.GenerateKeyPair(); // sous forme de base 64 comme nécsssaire pour l'envoi de la clé public vers le form //PrivateKeyInfo pkInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(keyPair.Private); //PrivateKey = Convert.ToBase64String( pkInfo.GetDerEncoded() ); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(lesdeuxcles.Public); PublicKey = Convert.ToBase64String(info.GetDerEncoded()); }
/// <summary> /// Constructor to be used to recover the existing RSA key pair and server /// signed certificate found on the local file system. /// </summary> /// <param name="passphrase">Passphrase for private key.</param> public RsaKeyPair(string passphrase) { if (!IsConfigured) { Configure(); } if (File.Exists(_clientPrivateKeyPemFile) && File.Exists(_clientCertPemFile)) { byte[] pkData = File.ReadAllBytes(_clientPrivateKeyPemFile); _pwd = passphrase.ToSecureString(); AsymmetricCipherKeyPair keyPair = PemDecodeKeyPair(pkData); // Generate key info's PrivateKeyInfo pkInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(keyPair.Private); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public); _privateKey = new EncryptionKey(KeyType.RSAPrivate, Convert.ToBase64String(pkInfo.GetDerEncoded()).ToSecureString(), EncryptionParameters.KEY_GENERATION_START); _publicKey = new EncryptionKey(KeyType.RSAPublic, Convert.ToBase64String(info.GetDerEncoded()).ToSecureString(), EncryptionParameters.KEY_GENERATION_START); byte[] certData = File.ReadAllBytes(_clientCertPemFile); X509CertificateParser certParser = new X509CertificateParser(); _certificate = certParser.ReadCertificate(certData); pkData = null; certData = null; keyPair = null; pkInfo = null; info = null; _pwd = null; GC.Collect(); } else { throw new Exception("Cannot find the PEM formatted certificate or private key file"); } }
public bool GenerarLLavesSoftware(string subject, string challenge, string fileName) { try { RsaKeyPairGenerator r = new RsaKeyPairGenerator(); var param = new RsaKeyGenerationParameters(new BigInteger("10001", 16), new SecureRandom(), 1024, 80); r.Init(param); AsymmetricCipherKeyPair k = r.GenerateKeyPair(); var privada = PrivateKeyInfoFactory.CreatePrivateKeyInfo(k.Private); SubjectPublicKeyInfo pubInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(k.Public); string priv = Convert.ToBase64String(privada.GetDerEncoded()); string pub = Convert.ToBase64String(pubInfo.GetDerEncoded()); File.WriteAllText("Privada.pem", priv); File.WriteAllText("Publica.pem", pub); RsaPrivateCrtKeyParameters privateKey = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(priv)); RsaKeyParameters publicKey = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.FromBase64String(pub)); DerSet derset = null; if (challenge != null) { ChallengePassword chpass = new ChallengePassword(challenge); derset = new DerSet(chpass); } else { derset = new DerSet(); } X509Name sub = new X509Name(subject, new ConverterSidetec()); Pkcs10CertificationRequest ds = new Pkcs10CertificationRequest("SHA1WITHRSA", sub, publicKey, derset, privateKey); File.WriteAllBytes(fileName, ds.GetDerEncoded()); return(true); } catch (Exception ee) { Log.Error(ee.Message); return(false); } }
public async Task <RsaKeyPair> CreateKeyPair() { var kpgen = new RsaKeyPairGenerator(); var privateKey = string.Empty; var publicKey = string.Empty; kpgen.Init(new KeyGenerationParameters(new SecureRandom(), 2048)); await Task.Run(() => { var keyPair = kpgen.GenerateKeyPair(); PrivateKeyInfo pkInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(keyPair.Private); privateKey = Convert.ToBase64String(pkInfo.GetDerEncoded()); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public); publicKey = Convert.ToBase64String(info.GetDerEncoded()); }); return(new RsaKeyPair { PrivateKey = privateKey, PublicKey = publicKey }); }
// This is less than ideal, but it seems to be the best way of supporting this without exposing SHA-1 // as the class is only used to workout the MSOutlook Key ID, you can think of the fact it's SHA-1 as // a coincidence... internal static byte[] CalculateKeyId(SubjectPublicKeyInfo info) { Sha1Digest dig = new Sha1Digest(); byte[] hash = new byte[dig.GetDigestSize()]; byte[] spkiEnc = new byte[0]; try { spkiEnc = info.GetDerEncoded(); } catch (IOException) { return(new byte[0]); } // try the outlook 2010 calculation dig.BlockUpdate(spkiEnc, 0, spkiEnc.Length); dig.DoFinal(hash, 0); return(hash); }
public byte[] GetBlob() { // get private key as byte array, and length of private key as byte array. PrivateKeyInfo info = PrivateKeyInfoFactory.CreatePrivateKeyInfo(_keyPair.Private); byte[] priv = info.GetDerEncoded(); byte[] privLen = BitConverter.GetBytes((Int32)priv.Length); // get public key as byte array. AsymmetricKeyParameter pubKey = _keyPair.Public; SubjectPublicKeyInfo spki = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(pubKey); byte[] pub = spki.GetDerEncoded(); // output byte array uses first 4 bytes for the length of the base64 private key, // followed by the base64 private key, then the base64 public key. // this is a completely homegrown non-standard format; for testing only. byte[] result = new byte[privLen.Length + priv.Length + pub.Length]; privLen.CopyTo(result, 0); priv.CopyTo(result, privLen.Length); pub.CopyTo(result, privLen.Length + priv.Length); return(result); }
public IActionResult Index() { var id = _userManager.GetUserId(User); var user = _aadeDbIntegration.GetUser(id); // first time there is no public/private key pair for encryption // so generate now // generated keypair using RSA that is unique to this aade user // https://cryptobook.nakov.com/asymmetric-key-ciphers/the-rsa-cryptosystem-concepts if (string.IsNullOrEmpty(user.PrivateKey)) { var keyGenerator = new RsaKeyPairGenerator(); var param = new KeyGenerationParameters( new SecureRandom(), 4096); keyGenerator.Init(param); var keyPair = keyGenerator.GenerateKeyPair(); // need to save these keys in the db so must serialize into strings // https://stackoverflow.com/questions/22008337/generating-keypair-using-bouncy-castle PrivateKeyInfo pkInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(keyPair.Private); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public); var aadeprivateKey = Convert.ToBase64String(pkInfo.GetDerEncoded()); var aadepublicKey = Convert.ToBase64String(info.GetDerEncoded()); user.PrivateKey = aadeprivateKey; user.PublicKey = aadepublicKey; _aadeDbIntegration.UpdateUser(user); } var model = new HomeViewModel(); var m = _messageDbIntegration.GetMessageForAadeUser(id); model.MyMessages = m; return(View(model)); }
/// <summary> /// Create random EC private key based on secp256r1 /// </summary> public static string CreatePrivateKey() { // creating private key SecureRandom secureRandom = new SecureRandom(); X9ECParameters ecParams = SecNamedCurves.GetByName("secp256r1"); ECDomainParameters ccdParams = new ECDomainParameters(ecParams.Curve, ecParams.G, ecParams.N, ecParams.H, ecParams.GetSeed()); ECKeyGenerationParameters keyGenParams = new ECKeyGenerationParameters(ccdParams, secureRandom); ECKeyPairGenerator generator = new ECKeyPairGenerator("ECDH"); generator.Init(keyGenParams); // getting public key AsymmetricCipherKeyPair keyPair = generator.GenerateKeyPair(); ECPrivateKeyParameters privParams = keyPair.Private as ECPrivateKeyParameters; PrivateKeyInfo privInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(privParams); ECPoint q = privParams.Parameters.G.Multiply(privParams.D); ECPublicKeyParameters pubParams = new ECPublicKeyParameters(privParams.AlgorithmName, q, privParams.Parameters); SubjectPublicKeyInfo pubInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(pubParams); // ugly hack byte[] der = privInfo.GetDerEncoded(); byte[] privateKey = der.Skip(der.Length - 32).ToArray(); der = pubInfo.GetDerEncoded(); byte[] publicKey = der.Skip(der.Length - 65).ToArray(); // repack DER DerSequence seq = new DerSequence( new DerInteger(1), new DerOctetString(privateKey), new DerTaggedObject(0, new DerObjectIdentifier("1.2.840.10045.3.1.7")), new DerTaggedObject(1, new DerBitString(publicKey)) ); der = seq.GetDerEncoded(); return(Hex.ToHexString(der)); }
/// <summary> /// Gets the kid for docker registry. /// </summary> /// <param name="certificate"></param> /// <returns></returns> private static string GetKid(X509Certificate2 certificate) { X509Certificate bouncyCert = DotNetUtilities.FromX509Certificate(certificate); AsymmetricKeyParameter bouncyPublicKey = bouncyCert.GetPublicKey(); SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(bouncyPublicKey); var encoded = info.GetDerEncoded(); using (SHA256Managed sha256 = new SHA256Managed()) { byte[] hash = sha256.ComputeHash(encoded); //Take the first 30 bytes byte[] sub = hash .Take(30) .ToArray(); string base32 = Base32.Encode(sub); return(FormatKid(base32)); } }
/// <summary> /// 从证书中提取公钥并转换为PEM编码 /// </summary> /// <param name="input">证书</param> /// <returns>PEM编码公钥</returns> public static string ExtractPemPublicKeyFromCert(X509Certificate input) { SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(input.GetPublicKey()); return(Convert.ToBase64String(subjectPublicKeyInfo.GetDerEncoded())); }
static void Main(string[] args) { Console.WriteLine("======== Mixin C# SDK Test ========= \n"); MixinApi mixinApi = new MixinApi(); mixinApi.Init(USRCONFIG.ClientId, USRCONFIG.ClientSecret, USRCONFIG.SessionId, USRCONFIG.PinToken, USRCONFIG.PrivateKey); Console.WriteLine("======== Initiation Finished ========= \n"); Console.WriteLine("======== Test Create PIN ===========\n"); //Console.WriteLine(mixinApi.CreatePIN(USRCONFIG.PinCode, "123456").ToString()); Console.WriteLine(); //Console.WriteLine(mixinApi.CreatePIN("123456", USRCONFIG.PinCode).ToString()); Console.WriteLine("\n\n======== Test Verify PIN ===========\n"); //Console.WriteLine(mixinApi.VerifyPIN(USRCONFIG.PinCode).ToString()); Console.WriteLine("\n\n======== Test Deposit ===========\n"); Console.WriteLine(mixinApi.Deposit("3596ab64-a575-39ad-964e-43b37f44e8cb").ToString()); Console.WriteLine("\n\n======== Test Read Assets ===========\n"); var assets = mixinApi.ReadAssets(); foreach (var asset in assets) { Console.WriteLine(asset.ToString()); Console.WriteLine(); } Console.WriteLine("\n\n======== Test Read Asset ===========\n"); Console.WriteLine(mixinApi.ReadAsset("6cfe566e-4aad-470b-8c9a-2fd35b49c68d")); Console.WriteLine("\n\n======== Test Search Assest ===========\n"); assets = mixinApi.SearchAssets("CNB"); foreach (var asset in assets) { Console.WriteLine(asset.ToString()); Console.WriteLine(); } Console.WriteLine("\n\n======== Test Network Asset ===========\n"); Console.WriteLine(mixinApi.NetworkAsset("965e5c6e-434c-3fa9-b780-c50f43cd955c")); Console.WriteLine("\n\n======== Test Top Assets ===========\n"); var topasset = mixinApi.TopAssets(); foreach (var asset in topasset) { Console.WriteLine(asset.ToString()); Console.WriteLine(); } Console.WriteLine("\n\n======== Test Network Snapshot don't auth ===========\n"); Console.WriteLine(mixinApi.NetworkSnapshot("85b8c435-1ef6-4f2a-85f9-8def2a852473", false)); Console.WriteLine("\n\n======== Test Network Snapshot auth ===========\n"); Console.WriteLine(mixinApi.NetworkSnapshot("85b8c435-1ef6-4f2a-85f9-8def2a852473", true)); Console.WriteLine("\n\n======== Test Network Snapshots ===========\n"); var snaps = mixinApi.NetworkSnapshots(2, "2019-01-02T15:04:05.999999999-07:00", null, null, false); foreach (var sn in snaps) { Console.WriteLine(sn.ToString()); Console.WriteLine(); } snaps = mixinApi.NetworkSnapshots(2, "2019-01-02T15:04:05.999999999-07:00", null, null, true); foreach (var sn in snaps) { Console.WriteLine(sn.ToString()); Console.WriteLine(); } Console.WriteLine("\n\n======== External Transactions ===========\n"); var ts = mixinApi.ExternalTransactions("6cfe566e-4aad-470b-8c9a-2fd35b49c68d", null, null, null, 10, null); foreach (var t in ts) { Console.WriteLine(t.ToString()); Console.WriteLine(); } Console.WriteLine("\n\n======== Test Create Address ===========\n"); //var addr = mixinApi.CreateAddress("965e5c6e-434c-3fa9-b780-c50f43cd955c", "0xe6Bf2C2E8f3243dF46308ca472038eA9Fa1bc42C", "CNB withdraw", null, null, USRCONFIG.PinCode); //Console.WriteLine(addr); Console.WriteLine("\n\n======== Test Create Address ===========\n"); //addr = mixinApi.CreateAddress("965e5c6e-434c-3fa9-b780-c50f43cd955c", "0x078C5AF6C8Ab533b8ef7FAb822B5B5f70A9d1c35", "CNB withdraw123", null, null, USRCONFIG.PinCode); //Console.WriteLine(addr); Console.WriteLine("\n\n======== Test Read Address ===========\n"); //Console.WriteLine(mixinApi.ReadAddress(addr.address_id)); Console.WriteLine("\n\n======== Test Delete Address ===========\n"); //Console.WriteLine(mixinApi.DeleteAddress(USRCONFIG.PinCode, addr.address_id)); Console.WriteLine("\n\n======== Test Withdrawal Addresses ===========\n"); var addrlist = mixinApi.WithdrawalAddresses("965e5c6e-434c-3fa9-b780-c50f43cd955c"); foreach (var a in addrlist) { Console.WriteLine(a.ToString()); Console.WriteLine(); } Console.WriteLine("\n\n======== Test Withdrawal ===========\n"); //Console.WriteLine(mixinApi.Withdrawal(addrlist[0].address_id, "100", USRCONFIG.PinCode, System.Guid.NewGuid().ToString(), "Test withdraw")); Console.WriteLine("\n\n======== Test Search User ===========\n"); var u = mixinApi.SearchUser("31243"); Console.WriteLine(u); Console.WriteLine("\n\n======== Test Read User ===========\n"); Console.WriteLine(mixinApi.ReadUser("cf0b9c0e-a80a-4044-a6dc-797400c148d7")); Console.WriteLine("\n\n======== Test Transfer ===========\n"); //Console.WriteLine(mixinApi.Transfer("965e5c6e-434c-3fa9-b780-c50f43cd955c", "cf0b9c0e-a80a-4044-a6dc-797400c148d7", "100", USRCONFIG.PinCode, System.Guid.NewGuid().ToString(), "Test Transfer")); Console.WriteLine("\n\n======== Test Verify Payment ===========\n"); Console.WriteLine(mixinApi.VerifyPayment("965e5c6e-434c-3fa9-b780-c50f43cd955c", "cf0b9c0e-a80a-4044-a6dc-797400c148d7", "100", "414c95cc-d695-48df-b23b-00815b21ed00")); Console.WriteLine("\n\n======== Test Read Transfer ===========\n"); Console.WriteLine(mixinApi.ReadTransfer("414c95cc-d695-48df-b23b-00815b21ed00")); Console.WriteLine("\n\n======== Test APP User ===========\n"); var kpgen = new RsaKeyPairGenerator(); kpgen.Init(new KeyGenerationParameters(new SecureRandom(new CryptoApiRandomGenerator()), 1024)); var keyPair = kpgen.GenerateKeyPair(); AsymmetricKeyParameter privateKey = keyPair.Private; AsymmetricKeyParameter publicKey = keyPair.Public; SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public); string pk = Convert.ToBase64String(info.GetDerEncoded()); var user = mixinApi.APPUser("Csharp" + (new Random().Next() % 100) + "test", pk); Console.WriteLine(user); Console.WriteLine("\n\n======== Test Read Profile ===========\n"); Console.WriteLine(mixinApi.ReadProfile()); Console.WriteLine("\n\n======== Test Update Profile ===========\n"); Console.WriteLine(mixinApi.UpdateProfile("mixin_csharp_sdk_demo", "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAAK/INwWK6QAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAAB3RJTUUH4wEJAgwnFleLvwAAEWhJREFUaN61mXmMXVd9xz/nnLu8bfbNY4+dOCZ2bJOoIRskbKLQQJpUgbD8QdWyFpWyCRpQoSrQShVFLFUqBahUGkGRKEVBVgqEUoJLgCQkBBLHOI4dO9jO2GN7tjdvu/csv/5x74xnbIdCoEf6+ln33Tnn+z2/9ZyneJZj3+GnOVlbzwXMcdT3c7IHTSvsHNLRTE/qCjUoUAMiBQ4lbQ0LG+u68/NZ7/pixURFWO/nOK6HGOmd4OLNF/zGPNSzIX/P4SYpjhOhxiO9lJcP2eGWU8/NA1d54TLgQqMYU4qKAiPgRegGOIlwONY8kmge7Itk74OtePGiKGNSt8iJuPaCwf8/Ad974jSTeol9YZzXXPiQuuvo1dss6mYn6qaA2hlrNVCLoBYpYg1GgVIgAl4gD0LXQdcLLjCvFY/GyF2pDrte9YPKwW+9OONVU10ePpVyxWTtdyfggaNNZrqQ6MBB28/GqLMpw7zNinpj7rkoMYqRiqY/KYgvTyrnWUiAPEAzF2azgA9IxXAg0XJHPeKOp9r6+Na+gBXF1qjJBZNjv52Ag0emua89SEUHptI8Ppqlr85Ff7DruSL3wmhVM1nXxPr/3gs5a8HcC9OdwHwmVA1Si9R9VcMnLhky3zq44HzLKV5/ceXZC3jsiUP8V2eK9WlOI1aDTcuHup53tqz0O4EL+g3jNfNrmfoZRYkw0wkcbXlSrRhI9Vwt4jOjsb9t0aqlJae5OG1x9ebzW+IZBXzz8TmezlOqRmhEYWLJ6k+2nPxxMw/ai+KiQcPEb0l+9Tje9jzV9CRGMZRq15+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Z2h0ADEyOEN8QYAAAAAXdEVYdFRodW1iOjpJbWFnZTo6V2lkdGgAMTI40I0R3QAAABl0RVh0VGh1bWI6Ok1pbWV0eXBlAGltYWdlL3BuZz+yVk4AAAAXdEVYdFRodW1iOjpNVGltZQAxNTQ2OTcxMTU59OK0DQAAABJ0RVh0VGh1bWI6OlNpemUAMTYxODVCiLvlAQAAAGJ0RVh0VGh1bWI6OlVSSQBmaWxlOi8vL2hvbWUvd3d3cm9vdC9uZXdzaXRlL3d3dy5lYXN5aWNvbi5uZXQvY2RuLWltZy5lYXN5aWNvbi5jbi9maWxlcy8xMDgvMTA4NjU1NS5wbmcDuUg9AAAAAElFTkSuQmCC")); Console.WriteLine("\n\n======== Test Update Perference ===========\n"); Console.WriteLine(mixinApi.UpdatePerference("CONTACTS", "CONTACTS")); Console.WriteLine(mixinApi.UpdatePerference("EVERYBODY", "EVERYBODY")); Console.WriteLine("\n\n======== Test Rotate User's QR ===========\n"); Console.WriteLine(mixinApi.RotateUserQR()); Console.WriteLine("\n\n======== Test Friends ===========\n"); var friends = mixinApi.Friends(); foreach (var f in friends) { Console.WriteLine(f); Console.WriteLine(); } Console.WriteLine("\n\n======== Test Create Attachment ===========\n"); Console.WriteLine(mixinApi.CreateAttachment()); Console.WriteLine("\n\n======== Test Create Conversation ===========\n"); var users = new List <ParticipantAction>(); users.Add(new ParticipantAction { action = "ADD", role = "", user_id = u.user_id }); Console.WriteLine(mixinApi.CreateConversation("GROUP", users)); Console.WriteLine(mixinApi.CreateConversation("CONTACT", users)); Console.WriteLine("\n\n======== Test Read Conversation ===========\n"); Console.WriteLine(mixinApi.ReadConversation("fd72abcd-b080-3e0e-bfea-a0b1282b4bd0")); mixinApi.WebSocketConnect(HandleOnRecivedMessage).Wait(); mixinApi.StartRecive(); do { var msg = Console.ReadLine(); mixinApi.SendTextMessage("fd72abcd-b080-3e0e-bfea-a0b1282b4bd0", msg).Wait(); } while (true); }
public FirstTimeSetup() { InitializeComponent(); //create the password entry view PasswordEntryView pep = new PasswordEntryView(); pep.OnSave += new EventHandler((o, e) => { //get the public key ASN1 SubjectPublicKeyInfo pubki = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(m_keypair.Public); //get the private key ASN1 PrivateKeyInfo privki = PrivateKeyInfoFactory.CreatePrivateKeyInfo(m_keypair.Private); //encrypt the private key byte[] encPrivKey = Crypto.EncryptKey(privki.GetDerEncoded(), pep.Text); m_keypair = null; //delete the old notebooks if (Directory.Exists(NoteManager.GetNotebookDir())) { Directory.Delete(NoteManager.GetNotebookDir(), true); } //save the keys to file KeyManager.SaveKeys(encPrivKey, pubki.GetDerEncoded()); //erase the data Eraser.SecureErase(encPrivKey); //ask if the user wants to use a fingerprint IFingerprint fp = FingerprintFactory.GetInstance(); fp.InitReader(); if (fp.IsReady()) { Application.Current.MainPage = new FingerprintPage(new EventHandler((oo, ee) => { byte[] data = (byte[])oo; //page returns the encrypted password if (data != null) { //only if was not skipped //encrypt the password and save it ConfigFactory.GetInstance().EncryptedPassword = data; ConfigFactory.GetInstance().UseFingerprint = true; } else { ConfigFactory.GetInstance().EncryptedPassword = new byte[] { 0 }; ConfigFactory.GetInstance().UseFingerprint = false; } //trigger the setup complete event if (OnSetupComplete != null) { OnSetupComplete(this, new EventArgs()); } }), fp, pep.Text); } else { //trigger the setup complete event if (OnSetupComplete != null) { OnSetupComplete(this, new EventArgs()); } } }); //create the activity indicator layout StackLayout actLayout = new StackLayout() { VerticalOptions = LayoutOptions.CenterAndExpand }; ActivityIndicator actInd = new ActivityIndicator();; actLayout.Children.Add(actInd); actLayout.Children.Add(new Label() { Text = "Generating key pair", TextColor = Color.DarkGray, HorizontalTextAlignment = TextAlignment.Center }); TapRandomizer tapRnd = new TapRandomizer(); tapRnd.OnRandomized += new EventHandler((o, e) => { m_seed = tapRnd.Seed; //show wait animation actInd.IsRunning = true; this.Content = actLayout; //generate the key pair Crypto.StartGenerateKeypair(m_seed, new Crypto.GenCompleteEventHandler((keypair) => { m_keypair = keypair; //hide wait animation actInd.IsRunning = false; //show the password entry page this.Content = pep; })); }); this.Content = tapRnd; }
// # // Mixin Network support cryptocurrencies (2019-02-19) // # // |EOS|6cfe566e-4aad-470b-8c9a-2fd35b49c68d // # // |CNB|965e5c6e-434c-3fa9-b780-c50f43cd955c // # // |BTC|c6d0c728-2624-429b-8e0d-d9d19b6592fa // # // |ETC|2204c1ee-0ea2-4add-bb9a-b3719cfff93a // # // |XRP|23dfb5a5-5d7b-48b6-905f-3970e3176e27 // # // |XEM|27921032-f73e-434e-955f-43d55672ee31 // # // |ETH|43d61dcd-e413-450d-80b8-101d5e903357 // # // |DASH|6472e7e3-75fd-48b6-b1dc-28d294ee1476 // # // |DOGE|6770a1e5-6086-44d5-b60f-545f9d9e8ffd // # // |LTC|76c802a2-7c88-447f-a93e-c29c9e5dd9c8 // # // |SC|990c4c29-57e9-48f6-9819-7d986ea44985 // # // |ZEN|a2c5d22b-62a2-4c13-b3f0-013290dbac60 // # // |ZEC|c996abc9-d94e-4494-b1cf-2a3fd3ac5714 // # // |BCH|fd11b6e3-0b87-41f1-a41f-f0e9b49e5bf0 static void Main(string[] args) { MixinApi mixinApi = new MixinApi(); mixinApi.Init(ClientId, ClientSecret, SessionId, PinToken, PrivateKey); string PromptMsg; PromptMsg = "1: Create user and update PIN\n2: Read Bitcoin balance \n3: Read Bitcoin Address\n4: Read EOS balance\n"; PromptMsg += "5: Read EOS address\n6: Transfer Bitcoin from bot to new account\n7: Transfer Bitcoin from new account to Master\n"; PromptMsg += "8: Withdraw bot's Bitcoin\n8: Withdraw bot's EOS\na: Verify Pin\nd: Create Address and Delete it\nr: Create Address and read it\n"; PromptMsg += "q: Exit \nMake your choose:"; // Console.WriteLine(mixinApi.VerifyPIN(PinCode).ToString()); do { Console.WriteLine(PromptMsg); var cmd = Console.ReadLine(); if (cmd == "1") { var kpgen = new RsaKeyPairGenerator(); kpgen.Init(new KeyGenerationParameters(new SecureRandom(new CryptoApiRandomGenerator()), 1024)); var keyPair = kpgen.GenerateKeyPair(); AsymmetricKeyParameter privateKey = keyPair.Private; AsymmetricKeyParameter publicKey = keyPair.Public; SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyPair.Public); string pk = Convert.ToBase64String(info.GetDerEncoded()); var user = mixinApi.APPUser("Csharp" + (new Random().Next() % 100) + " Cat", pk); Console.WriteLine(user); using (var writer = new StreamWriter("new_users.csv", append: true)) using (var csv = new CsvWriter(writer)) { csv.WriteField(user.user_id); //Write Private key to CSV RsaPrivateCrtKeyParameters rsaParameters = (RsaPrivateCrtKeyParameters)privateKey; RSACryptoServiceProvider priKey = new RSACryptoServiceProvider(); priKey.ImportParameters(DotNetUtilities.ToRSAParameters(rsaParameters)); TextWriter pemText = new StringWriter(); ExportPrivateKey(priKey, pemText); csv.WriteField(pemText.ToString()); csv.WriteField(user.pin_token); csv.WriteField(user.session_id); csv.NextRecord(); csv.Flush(); //Update the pincode of New user MixinApi mixinApiNewUser = new MixinApi(); mixinApiNewUser.Init(user.user_id, "", user.session_id, user.pin_token, pemText.ToString()); Console.WriteLine(mixinApiNewUser.CreatePIN("", "123456").ToString()); } } if (cmd == "2" || cmd == "3") { using (TextReader fileReader = File.OpenText(@"new_users.csv")) { var csv = new CsvReader(fileReader); csv.Configuration.HasHeaderRecord = false; while (csv.Read()) { string UserIDNewUser; csv.TryGetField <string>(0, out UserIDNewUser); string PrivateKeyNewUser; csv.TryGetField <string>(1, out PrivateKeyNewUser); string PinTokenNewUser; csv.TryGetField <string>(2, out PinTokenNewUser); string SessionIDNewUser; csv.TryGetField <string>(3, out SessionIDNewUser); MixinApi mixinApiNewUser = new MixinApi(); mixinApiNewUser.Init(UserIDNewUser, "", SessionIDNewUser, PinTokenNewUser, PrivateKeyNewUser); Asset AssetBTC = mixinApiNewUser.ReadAsset(ASSET_ID_BTC); Console.WriteLine("New User " + UserIDNewUser + " 's BTC balance is " + AssetBTC.balance); Console.WriteLine("New User " + UserIDNewUser + " 's BTC address is " + AssetBTC.public_key); } } } if (cmd == "4" || cmd == "5") { using (TextReader fileReader = File.OpenText(@"new_users.csv")) { var csv = new CsvReader(fileReader); csv.Configuration.HasHeaderRecord = false; while (csv.Read()) { string UserIDNewUser; csv.TryGetField <string>(0, out UserIDNewUser); string PrivateKeyNewUser; csv.TryGetField <string>(1, out PrivateKeyNewUser); string PinTokenNewUser; csv.TryGetField <string>(2, out PinTokenNewUser); string SessionIDNewUser; csv.TryGetField <string>(3, out SessionIDNewUser); MixinApi mixinApiNewUser = new MixinApi(); mixinApiNewUser.Init(UserIDNewUser, "", SessionIDNewUser, PinTokenNewUser, PrivateKeyNewUser); Asset AssetEOS = mixinApiNewUser.ReadAsset(ASSET_ID_EOS); Console.WriteLine("New User " + UserIDNewUser + " 's EOS balance is " + AssetEOS.balance); Console.WriteLine("New User " + UserIDNewUser + " 's EOS address is " + AssetEOS.account_name + " " + AssetEOS.account_tag); } } } if (cmd == "6") { using (TextReader fileReader = File.OpenText(@"new_users.csv")) { var csv = new CsvReader(fileReader); csv.Configuration.HasHeaderRecord = false; while (csv.Read()) { string UserIDNewUser; csv.TryGetField <string>(0, out UserIDNewUser); Transfer reqInfo = mixinApi.Transfer(ASSET_ID_BTC, UserIDNewUser, AMOUNT, PinCode, System.Guid.NewGuid().ToString(), "Test"); Console.WriteLine(reqInfo); } } } if (cmd == "7") { using (TextReader fileReader = File.OpenText(@"new_users.csv")) { var csv = new CsvReader(fileReader); csv.Configuration.HasHeaderRecord = false; while (csv.Read()) { string UserIDNewUser; csv.TryGetField <string>(0, out UserIDNewUser); string PrivateKeyNewUser; csv.TryGetField <string>(1, out PrivateKeyNewUser); string PinTokenNewUser; csv.TryGetField <string>(2, out PinTokenNewUser); string SessionIDNewUser; csv.TryGetField <string>(3, out SessionIDNewUser); MixinApi mixinApiNewUser = new MixinApi(); mixinApiNewUser.Init(UserIDNewUser, "", SessionIDNewUser, PinTokenNewUser, PrivateKeyNewUser); // Console.WriteLine(mixinApiNewUser.CreatePIN("", "123456").ToString()); Transfer reqInfo = mixinApiNewUser.Transfer(ASSET_ID_BTC, MASTER_UUID, AMOUNT, "123456", System.Guid.NewGuid().ToString(), "Test"); Console.WriteLine(reqInfo); } } } if (cmd == "8") { var addr = mixinApi.CreateAddress(ASSET_ID_BTC, BTC_WALLET_ADDR, "BTC withdraw", null, null, PinCode); Console.WriteLine(addr); // Console.WriteLine(mixinApi.Withdrawal(addr.address_id,AMOUNT,PinCode,System.Guid.NewGuid().ToString(), "Test withdraw")); } if (cmd == "9") { var addr = mixinApi.CreateAddress(null, null, "EOS withdraw", "eoswithmixin", "d80363afcc466fbaf2daa7328ae2adfa", PinCode); Console.WriteLine(addr); // Console.WriteLine(mixinApi.Withdrawal(addr.address_id,AMOUNT,PinCode,System.Guid.NewGuid().ToString(), "Test withdraw")); } if (cmd == "q") { break; } if (cmd == "d") { var addr = mixinApi.CreateAddress(ASSET_ID_BTC, BTC_WALLET_ADDR, "BTC withdraw", null, null, PinCode); Console.WriteLine(addr); Console.WriteLine(mixinApi.DeleteAddress(PinCode, addr.address_id)); } if (cmd == "r") { var addr = mixinApi.CreateAddress(ASSET_ID_BTC, BTC_WALLET_ADDR, "BTC withdraw", null, null, PinCode); Console.WriteLine(addr); Console.WriteLine(mixinApi.ReadAddress(addr.address_id)); } if (cmd == "qs") { var assets = mixinApi.ReadAssets(); foreach (var asset in assets) { Console.WriteLine(asset.ToString()); Console.WriteLine(); } } if (cmd == "s") { var u = mixinApi.SearchUser("37222956"); Console.WriteLine(u); Console.WriteLine(u.user_id); Console.WriteLine(u.full_name); using (var writer = new StreamWriter("new_users.csv")) using (var csv = new CsvWriter(writer)) { csv.WriteField(u.user_id); csv.WriteField(u.full_name); csv.NextRecord(); csv.Flush(); } } } while (true); }