(C#)System.Security.SecureString(表示应保密的文本)
正常的String类型值,在脱离开作用域之后,其值在内存中并不会被立即销毁,这时如果有人恶意扫描你的内存,程序中所保存的机密信息就会暴露;于是就有了System.Security.SecureString,SecureString表示一个应保密的文本,它在初始化时就已被加密,并且脱离作用域后会被立即销毁;
附一个小Demo:
- class Program{
- static void Main(){
- System.Security.SecureString secureStr = new System.Security.SecureString();
- secureStr.AppendChar('A');
- string re = secureStr.ToString();//SecureString 中的值会被加密保存,不能直接获取,此时re=System.Security.SecureString
- IntPtr inP = Marshal.SecureStringToBSTR(secureStr);//inP为secureStr的句柄
- string ss = Marshal.PtrToStringBSTR(inP);//ss="A"
- Marshal.ZeroFreeBSTR(inP);//释放BSTR指针
- string ss2 = Marshal.PtrToStringBSTR(inP);//ss2=""
- }
- }
SecureString用法Demo
(C#)System.Security.SecureString(表示应保密的文本)的更多相关文章
- 17 安全字符串 System.Security.SecureString
- 使用证书部署出现System.Security.Cryptography.CryptographicException 错误解决方案
一.System.Security.Cryptography.CryptographicException: 找不到对象 at System.Security.Cryptography.Cryptog ...
- .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数
.Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...
- "System.Security.Cryptography.CryptographicException: 拒绝访问" 问题的解决方法
.net web程序使用rsa算法进行加解密时,程序报告“System.Security.Cryptography.CryptographicException: 拒绝访问”错.按网上搜的解决方法做了 ...
- System.Security.SecurityException The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception
[15/08/19 00:03:10] [DataManager-7292-ERROR] System.Reflection.TargetInvocationException: Exception ...
- System.Security.SecurityException The source was not found, but some or all event logs could not be searched.Inaccessible logs Security.
An exception occurred during the Install phase. System.Security.SecurityException The source was not ...
- System.Security.Cryptography.CryptographicException: 指定了无效的提供程序类型
这两天在调用银联在线的支付接口,把银联提供的demo代码copy过来放到自己网站上,生成通过了,但是运行的时候就报错了: 指定了无效的提供程序类型. 说明: 执行当前 Web 请求期间,出现未经处理的 ...
- System.Security.Cryptography.CryptographicException 出现了内部错误
调试微信支付退款时,需要使用pfx证书,在本地调试时没有问题,但在服务器部署时报异常:System.Security.Cryptography.CryptographicException 出现了内部 ...
- 部署时,出现用户代码未处理 System.Security.Cryptography.CryptographicException 错误解决方法
转载:http://www.cnblogs.com/jys509/p/4499978.html 在调用RSA加密的.pfx密钥时,在本地调试没有问题,可以布署到服务器,就会报以下的错误: 用户代码未处 ...
随机推荐
- windows SFC(System File Checker) 命令的使用
SFC(System File Checker)可以扫描所有受保护的系统文件的完整性,并使用正确的 Microsoft 版本替换. 步骤:点击开始,输入cmd: 右键,以管理员身份运行 输入sfc/s ...
- [Linux]nginx tomcat做负载均衡
之前使用nginx做过web反向代理,没有做过负载均衡,今天有个同学须要做tomcat的负载均衡,我也研究下. 一共是2个机器,一个物理机(win7)上面部署2个tomcat,使用不同的port启动. ...
- ylbtech-LanguageSamples-ComInteropPart2(COM 互操作第二部分)
ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-ComInteropPart2(COM 互操作第二部分) 1.A,示例(Sample) ...
- 实现一个Cglib代理Demo
Cglib动态代理采用的是创建目标类的子类的方式.优点:不用实现额外接口,只操作我们关心类,高性能. package jesse.test; import java.lang.reflect.Meth ...
- Android项目总结
功能: 1.图片载入 ImageLoader 參数配置要合理 cacheMemory 一次性的图片最好不要缓存在内存中 合理控制在内存中的内存大小 ,适当的释放 volley是googl ...
- Java 多线程之 synchronized 和 volatile 的比較
概述 在做多线程并发处理时,常常须要对资源进行可见性訪问和相互排斥同步操作.有时候,我们可能从前辈那里得知我们须要对资源进行 volatile 或是 synchronized 关键字修饰处理.但是,我 ...
- java web程序中项目名的更改(http://localhost:8080/)后面的名字
在MyEclipse中的Web项目,如果想另换名称(Context-root)进行发布,可以在项目的属性中进行设置.设置路径如下: 右击项目XX(或选中项目XX,按快捷键Alt+Enter), 打开项 ...
- 《暗黑世界V1.6》服务器代码执行图
<暗黑世界V1.6>服务器代码执行图 (原文地址:http://www.9miao.com/forum.php?mod=viewthread&tid=44016&highl ...
- MPJoystick
using UnityEngine; /** * File: MPJoystick.cs * Author: Chris Danielson of (monkeyprism.com) * // USE ...
- 微信小程序bindtap和catchtap区别
bindtap可以产生冒泡事件 catchtap只自身触发事件,不会传递到父视图 文章来源:刘俊涛的博客 地址:http://www.cnblogs.com/lovebing 欢迎关注 ...