Exemplo n.º 1
0
        /// <summary>
        /// Converts an object tree to a secure string.
        /// </summary>
        /// <param name="objectToSerialize">the object at the root of the object tree
        /// to protect.</param>
        /// <param name="encryptionKey">the key to use to encrypt the object</param>
        /// <param name="validationKey">ignored</param>
        /// <param name="encryptionAlgorithm">the name of the encryption algorithm to use, null means use default</param>
        /// <param name="validationAlgorithm">the name of the signing algorithm to use, null means use default</param>
        /// <returns>a secure string that can be passed to <see cref="Unprotect(string)"/> to
        /// retrieve the original object.</returns>
        /// <remarks>The encryption key and algorithms are used
        /// to encrypt the serialized object.  They must have
        /// the same values when <see cref="Unprotect(string, byte[], byte[])"/> is called or
        /// an exception will occur.</remarks>
        public static string Protect(object objectToSerialize, byte[] encryptionKey, byte[] validationKey, string encryptionAlgorithm, string validationAlgorithm)
        {
            SelfSerializingObject obj = new SelfSerializingObject();

            obj.Obj = objectToSerialize;
            return(Protect(obj.Serialize, encryptionKey, validationKey, encryptionAlgorithm, validationAlgorithm));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts a secure string back to the object tree it represents.
        /// </summary>
        /// <param name="secureString">a <see cref="string"/> returned by an earlier
        /// call to <see cref="Protect(object)"/></param>
        /// <param name="encryptionKey">the key to use to decrypt the ciphertext</param>
        /// <param name="validationKey">ignored</param>
        /// <param name="encryptionAlgorithm">the algorithm to use to decrypt the ciphertext, null means use the default</param>
        /// <param name="validationAlgorithm">the algorithm to use to verify the signature, null means use the default</param>
        /// <returns>the object that was passed to <see cref="Protect(object)"/></returns>
        /// <exception>throws an <see cref="Exception"/> if the signature is
        /// not valid.</exception>
        /// <remarks>The encryption key and algorithms must have
        /// the same values as they did when <see cref="Protect(object, byte[], byte[])"/> was called or
        /// an exception will occur.</remarks>
        public static object Unprotect(string secureString, byte[] encryptionKey, byte[] validationKey, string encryptionAlgorithm, string validationAlgorithm)
        {
            SelfSerializingObject obj = new SelfSerializingObject();

            Unprotect(secureString, encryptionKey, validationKey, encryptionAlgorithm, validationAlgorithm, obj.Deserialize, AssertSignaturesAreEqual);
            return(obj.Obj);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Converts a secure string back to the object tree it represents.
 /// </summary>
 /// <param name="secureString">a <see cref="string"/> returned by an earlier
 /// call to <see cref="Protect(object)"/></param>
 /// <param name="encryptionKey">the key to use to decrypt the ciphertext</param>
 /// <param name="validationKey">the key to use to verify the signature</param>
 /// <returns>the object that was passed to <see cref="Protect(object)"/></returns>
 /// <exception>throws an <see cref="Exception"/> if the signature is
 /// not valid.</exception>
 /// <remarks>The encryption and validation keys must have
 /// the same values as they did when <see cref="Protect(object, byte[], byte[])"/> was called or
 /// an exception will occur.</remarks>
 public static object Unprotect(string secureString, byte[] encryptionKey, byte[] validationKey)
 {
     SelfSerializingObject obj = new SelfSerializingObject();
     Unprotect(secureString, encryptionKey, validationKey, obj.Deserialize, AssertSignaturesAreEqual);
     return obj.Obj;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Converts an object tree to a secure string.
 /// </summary>
 /// <param name="objectToSerialize">the object at the root of the object tree
 /// to protect.</param>
 /// <param name="encryptionKey">the key to use to encrypt the object</param>
 /// <param name="validationKey">the key to use for signing</param>
 /// <returns>a secure string that can be passed to <see cref="Unprotect(string)"/> to
 /// retrieve the original object.</returns>
 /// <remarks>The encryption and validation keys are used
 /// to encrypt the serialized object and sign it, respectively.  They must have
 /// the same values when <see cref="Unprotect(string, byte[], byte[])"/> is called or
 /// an exception will occur.</remarks>
 public static string Protect(object objectToSerialize, byte[] encryptionKey, byte[] validationKey)
 {
     SelfSerializingObject obj = new SelfSerializingObject();
     obj.Obj = objectToSerialize;
     return Protect(obj.Serialize, encryptionKey, validationKey);
 }