コード例 #1
0
ファイル: MapType.cs プロジェクト: block-m3/aepp-sdk-net
        public override string Serialize(object o, Type t)
        {
            StringBuilder bld = new StringBuilder();

            if (o is IDictionary en)
            {
                bld.Append("{");
                bool add = false;
                foreach (object on in en.Keys)
                {
                    add = true;
                    bld.Append("[");
                    bld.Append(KeyType.Serialize(on, t.GetGenericArguments()[0]));
                    bld.Append("] = ");
                    bld.Append(ValueType.Serialize(en[on], t.GetGenericArguments()[1]));
                    bld.Append(", ");
                }

                if (add)
                {
                    bld.Remove(bld.Length - 2, 2);
                }
                bld.Append("}");
                return(bld.ToString());
            }

            return(base.Serialize(o, t));
        }
コード例 #2
0
ファイル: JWK.cs プロジェクト: bently0602/JWK
        public string Export(bool shouldExportPrivateKey = false)
        {
            #if DEBUG
            var performanceStopWatch = new Stopwatch();
            performanceStopWatch.Start();
            #endif

            _shouldExportPrivateKey = shouldExportPrivateKey;

            if (!shouldExportPrivateKey && IsSymmetric())
            {
                throw new CryptographicException("Symetric key of type " + KeyType.Serialize() + " cannot be exported with shouldExportPrivateKey set to false.");
            }

            var jwkJSON = JsonConvert.SerializeObject(this);

            #if DEBUG
            performanceStopWatch.Stop();
            Console.WriteLine($"Debug Information - CreativeCode.JWK - Succesfully serialized JWK of type '{KeyType.Type}'. It took {performanceStopWatch.Elapsed.TotalMilliseconds}ms.");
            #endif

            return(jwkJSON);
        }