当前位置: 首页>>代码示例>>C#>>正文


C# SecureString.ToByteArray方法代码示例

本文整理汇总了C#中System.Security.SecureString.ToByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# SecureString.ToByteArray方法的具体用法?C# SecureString.ToByteArray怎么用?C# SecureString.ToByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.SecureString的用法示例。


在下文中一共展示了SecureString.ToByteArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Decrypt

 public static byte[] Decrypt(byte[] encryptionPayload, SecureString passPhrase)
 {
     var passwordBytes = passPhrase.ToByteArray();
     var output = Decrypt(encryptionPayload, passwordBytes);
     passwordBytes.ClearByteArray();
     return output;
 }
开发者ID:compliashield,项目名称:compliashield-sdk-encryption,代码行数:7,代码来源:AesEncryptor.cs

示例2: SecureStringExtensions_ToByteArray_EmptyInput

 public void SecureStringExtensions_ToByteArray_EmptyInput()
 {
     SecureString input = new SecureString();
     byte[] output = input.ToByteArray();
     byte[] expected = new byte[0];
     CollectionAssert.AreEqual(expected, output);
 }
开发者ID:deimx42,项目名称:DSInternals,代码行数:7,代码来源:SecureStringExtensionsTester.cs

示例3: Encrypt

 public static string Encrypt(SecureString input)
 {
     Validator.AssertNotNull(input, "input");
     if(input.Length == 0)
     {
         return String.Empty;
     }
     byte[] bytes = input.ToByteArray();
     try
     {
         // Encrypt
         var aes = new AesCryptoServiceProvider();
         // Set nulled IV
         aes.IV = new byte[aes.IV.Length];
         aes.Key = AesKey;
         ICryptoTransform aesEncryptor = aes.CreateEncryptor();
         // Decrypt
         byte[] encryptedBytes = aesEncryptor.TransformFinalBlock(bytes, 0, bytes.Length);
         // Convert to Base64
         string base64 = Convert.ToBase64String(encryptedBytes);
         // Remove Base64 padding
         string result = RemoveBase64Padding(base64);
         return result;
     }
     finally
     {
         bytes.ZeroFill();
     }
 }
开发者ID:deimx42,项目名称:DSInternals,代码行数:29,代码来源:GPPrefPwdObfuscator.cs

示例4: Encrypt_Private_v1

 private static byte[] Encrypt_Private_v1(byte[] unencryptedBytes, SecureString passPhrase, int iterations)
 {
     var passPhraseAsBytes = passPhrase.ToByteArray();
     var payload = Encrypt_Private_v1(unencryptedBytes, passPhraseAsBytes, iterations);
     passPhraseAsBytes.ClearByteArray(); // modify the byte array
     return payload;
 }
开发者ID:compliashield,项目名称:compliashield-sdk-encryption,代码行数:7,代码来源:AesEncryptor.cs

示例5: EncryptToBase64StringAsync

        //[Obsolete]
        //public static string EncryptToBase64String(SecureString passwordToProtect, string keyId, RSACryptoServiceProvider publicKey)
        //{
        //    return EncryptToBase64String(passwordToProtect, keyId, publicKey, null, null);
        //}


        ///// <summary>
        ///// This may be used to secure a password for symmetric encryption.
        ///// </summary>
        ///// <param name="passwordToProtect"></param>
        ///// <param name="publicKey"></param>
        ///// <returns></returns>
        //[Obsolete("Use the IPublicKey infrastructure")]
        //public static string EncryptToBase64String(SecureString passwordToProtect, string key1Id, RSACryptoServiceProvider publicKey1, string key2Id, RSACryptoServiceProvider publicKey2)
        //{
        //    // Use a 4-byte array to fill it with random bytes and convert it then
        //    // to an integer value.
        //    byte[] plainBytes;
        //    //byte[] encryptedBytes = null;

        //    plainBytes = passwordToProtect.ToByteArray();

        //    var asymEnc = new AsymmetricEncryptor(AsymmetricStrategyOption.Aes256_1000);
        //    var asymObj = asymEnc.EncryptObject(plainBytes, key1Id, publicKey1, key2Id, publicKey2);
        //    var json = Serializer.SerializeToJson(asymObj);
        //    var bytes = Encoding.UTF8.GetBytes(json);
        //    return Convert.ToBase64String(bytes);
        //}

        /// <summary>
        /// This may be used to secure a password for symmetric encryption.
        /// </summary>
        /// <param name="passwordToProtect"></param>
        /// <param name="publicKey"></param>
        /// <returns></returns>
        public static async Task<string> EncryptToBase64StringAsync(SecureString passwordToProtect, IPublicKey publicKey1, IPublicKey publicKey2)
        {
            // Use a 4-byte array to fill it with random bytes and convert it then
            // to an integer value.
            byte[] plainBytes;
            //byte[] encryptedBytes = null;

            plainBytes = passwordToProtect.ToByteArray();

            var asymEnc = new AsymmetricEncryptor(AsymmetricStrategyOption.Aes256_1000);
            var asymObj = await asymEnc.EncryptObject_PrivateAsync(plainBytes, publicKey1, publicKey2);
            var json = Serializer.SerializeToJson(asymObj);
            var bytes = Encoding.UTF8.GetBytes(json);
            return Convert.ToBase64String(bytes);
        }
开发者ID:compliashield,项目名称:compliashield-sdk-encryption,代码行数:51,代码来源:AsymmetricEncryptor.cs


注:本文中的System.Security.SecureString.ToByteArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。