中国网络渗透测试联盟

标题: web.Config加密解密最简单实用方法 [打印本页]

作者: admin    时间: 2013-8-5 15:33
标题: web.Config加密解密最简单实用方法
web.config的文件多数的时候不希望别人看到,下面提供一个加密,解密的语句,简洁方便实用,先看到效果,至于加密的原理其他的网页上做了很多说明,这里只演示效果。3 o- C, K( q& l* C3 t( a4 l
  加密前的connectionStrings节点
0 t5 q0 L: p" M9 X' ?0 E! @  代码
3 Z) U0 `0 ]" s1 o  <connectionStrings>
. c5 D$ H8 m4 x. d  <add name="SQLConnString1" connectionString="server=WJW-PC\SQL2008;user id=sa;password=12345;Initial Catalog=dbFASH;min pool size=4;max pool size=400;" />
% W* q; Y( \% \6 w4 {  <add name="eziyaConnectionString1" connectionString="Data Source=HOME-COMPUTER;Initial Catalog=dbFASH;Integrated Security=True;MultipleActiveResultSets=Falseacket Size=4096;Application Name=&quot;Microsoft SQL Server Management Studio&quot;"
' ]# L) \( ?/ A/ A7 _  providerName="System.Data.SqlClient" />8 A6 q9 [  f+ S; S( Z
  <add name="eziyaConnectionString2" connectionString="Data Source=192.168.1.200;Initial Catalog=dbFASHersist Security Info=True;User ID=taoka;MultipleActiveResultSets=Falseacket Size=4096;Application Name=&quot;Microsoft SQL Server Management Studio&quot;"9 s$ h: o; x; [4 Y& R, @3 C
  providerName="System.Data.SqlClient" />
* J7 T3 M6 \7 A, A& P" y/ t8 Y  <add name="eziyaConnectionString3" connectionString="Data Source=192.168.61.160;Initial Catalog=dbFASHersist Security Info=True;User ID=sa;MultipleActiveResultSets=Falseacket Size=4096;Application Name=&quot;Microsoft SQL Server Management Studio&quot;"% G6 C- L( b, P( s2 L( i& F5 v
  providerName="System.Data.SqlClient" />
/ J% u9 S- H7 K# |: m, U0 U1 o* \! z  </connectionStrings>9 z, D9 L8 P/ b" Q2 l) t- @
  加密后的connectionStrings的节点0 m) Y/ A8 l) G7 Y9 r2 Z
  代码
9 a5 B' e: Q) `' s8 V7 H, m  b  <connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
0 z. N$ L" H0 V/ }, p  <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
: V( m5 {7 \$ d6 A2 o. a! r  xmlns="http://www.w3.org/2001/04/xmlenc#"&gt;+ y5 o6 \$ R& p2 ^" N
  <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
9 H* w, L6 ]  M+ c% X% T0 e2 o) r+ D  <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;
# M  C0 K0 D6 X% C% Y  <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#"&gt;1 i2 J+ @2 ?) B( o! ~
  <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /># k) G5 ~! u7 k1 I
  <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;
3 J- F& Q  j2 p% ~' L4 q  <KeyName>Rsa Key</KeyName>9 p5 D; p, u4 M) G$ @
  </KeyInfo>+ N- a$ L9 }8 l$ S0 K( M
  <CipherData>
0 t  F* ~  T+ {! I3 T+ n7 H  <CipherValue>FOkydQFNniZvq71ua4XapuVCUrJFOARkXeqqwyKFoP+NGXGewehxYW0zTzIn/j+YCvH/r6ABoE/AfWMMEDyr81R1mhi4ckXbiJ2BvW612/W7f7Wkqj+FDwse+lgAISHZ5HfspaY1LBvKYAu1VEm6Iu6NlT35TPnjxFf+p5Apf0E=</CipherValue>
7 F( ^; {* e+ M& ?  </CipherData>
8 V; r  W9 A7 l  </EncryptedKey>
! y6 m8 U9 }/ W9 Q7 M  </KeyInfo>! G# V1 ]1 X& q
  <CipherData>6 j, N& h0 \' i
  <CipherValue>s3PKarSQ/tlnG5YcE/z/KLbnSLljw/nOj+aoafGD9eJRlZ092f5Ywx9IDRaKMqNQ6+OM3f0WOh57evnWqL8tjULwNHviMAP3RU/5CTCGfZ/k0u+jWAGYYuOxlT6/iKsMbceBGh5jmcwIG+d3itc+h+Qq5B3g8Jjbt8Y+IulmOYWEnp2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aOvEu4WGv3WT25FFiYLdO99uzXOPn7UTolUqmkYlYelgh5n5QmFd4WsqOt4oYE5CFadI/n/MsLpVJmJTzA+8CAD26cpuOmloyHzsEpqUWZb5lAO9jfDVu9F6SznBr0iaCkko5jw2kZw4tqRx2B+9eUNPTQGRPRVgc5stAFVf13w974sRrwCvGRSq0U/71cBSE8KSLOj/aGf2p4UBSUPRk=</CipherValue>' L. K4 f" C- ], T) Z+ q8 @
  </CipherData>0 l7 F: R3 W% B) x
  </EncryptedData>. \3 B8 X( T3 s5 Y- |) E! E/ f
  </connectionStrings>
  [2 b3 J: L3 [& O5 W9 e  完全看不到连接的信息!  [1 O9 {6 N: {8 O# E( k
  下面是两个.bat批处理文件+ E  u; l6 f* ?2 A2 O2 x
  加密:! \7 C8 R! v$ q, h$ E- D
  @echo off
$ A/ Q1 g4 F9 @8 E! L* D( G8 H  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -pef "connectionStrings" "E:\code\proj\Web"
7 c% Q( r) N+ c' h  解密:
8 B: _- I& X! r  @echo off3 ^( _- D# g4 M; ^3 a3 d5 Q/ x7 Y
  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -pdf "connectionStrings" "E:\code\proj\Web"$ c3 O. B0 L1 s2 l$ D- x5 _
  PAUSE4 q; w+ J, f- d4 p* H. }
  直接将语句拷贝到.BAT文件中,E:\code\proj\Web为相应的web.config所在的路径,只能在一台电脑上操作,否则不可逆
作者: Anthony~    时间: 2013-8-5 19:31
好方法。我正好刚遇到这个问题




欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/) Powered by Discuz! X3.2