(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密钥时,在本地调试没有问题,可以布署到服务器,就会报以下的错误: 用户代码未处 ...
随机推荐
- asp.net mvc视图引擎
继上周介绍了Razor之后,ASP.NET MVC 现在已有四种主要的视图引擎.其他三种引擎是Spark.NHaml和传统的ASPX文件模板.本文将大致介绍这四种引擎,并着重讨论新的Razor引 擎. ...
- Tomcat环境下配置数据源
两种方式,图形化和字符型配置,图形化需要部署一个应用,字符型配置如下: 需要文件 mysql-connector-java-5.1.16-bin.jar Oracle需要classes12.jar文件 ...
- 判断浏览器是否支持 JS
在有些浏览器中不支持(或者被禁用了)脚本语言,那么javascript脚本则无法被执行.但是用户并不知道浏览器是否支持,或者被禁用.我们可以通过<noscript>标签来告知用户,JS脚运 ...
- 算法导论-求x的n次方
目录 1.分治求x的n次方思路 2.c++代码实现 内容 1.分治求x的n次方思路T(n)=Θ(lgn) 为了计算乘方数a^n,传统的做法(所谓的Naive algorithm)就是循环相乘n次,算法 ...
- 数据挖掘算法之关联规则挖掘(二)FPGrowth算法
之前介绍的apriori算法中因为存在许多的缺陷,例如进行大量的全表扫描和计算量巨大的自然连接,所以现在几乎已经不再使用 在mahout的算法库中使用的是PFP算法,该算法是FPGrowth算法的分布 ...
- node - 导包机制
在学node js的时候,经常各种导包 let http = require('http'); 然后它的运行机制: 1. 查找当前目录下面的node_modules 2. 全局查找(首先添加到path ...
- CSS--百度百科
层叠样式表是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言. CSS目前最新版本为CSS3,是能够真正做到网页表现与内容分离的一种样式设 ...
- 【Java】Java_08 字符型与布尔值
1.字符型(2个字节) 单引号用来表示字符常量.例如‘A’是一个字符,它与“A”是不同的,“A”表示含有一个字符的字符串 char 类型用来表示在Unicode编码表中的字符 Unicode编码被设计 ...
- XAOP的使用示范例子
代码地址如下:http://www.demodashi.com/demo/12976.html XAOP 一个简易的AOP(Android)应用框架.囊括了最实用的AOP应用. 特点 支持快速点击切片 ...
- PLSQL中scott账户登录不上,报错ORA-01017: invalid username/password; logon denied
问题:PLSQL中scott账户登录不上,提示上述错误 解决方法: 1. cmd——>进入c目录; 2. 输入:sqlplus/nolog; 3. connect username/passwo ...