示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="serialized"></param>
        /// <returns></returns>
        public static AsymmetricCipherKeyPair Unserialize(string serialized)
        {
            KeyPairStore store = JsonConvert.DeserializeObject <KeyPairStore>(serialized);

            RsaPrivateCrtKeyParameters privateKey = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(store.PrivateKey));
            RsaKeyParameters           publicKey  = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.FromBase64String(store.PublicKey));

            return(new AsymmetricCipherKeyPair(publicKey, privateKey));
        }
示例#2
0
        /// <summary>
        /// Serialize a pair of public/private keys
        /// </summary>
        /// <param name="pair"></param>
        public static string Serialize(AsymmetricCipherKeyPair pair)
        {
            var store = new KeyPairStore()
            {
                PublicKey  = SerializePublicKey(pair.Public),
                PrivateKey = SerializePrivateKey(pair.Private)
            };

            return(store.SerializeToJson());
        }