@@ -16,6 +16,20 @@ static void Main(string[] args)
1616 Console . WriteLine ( "===========================" ) ;
1717 Console . WriteLine ( ) ;
1818
19+ // Prompt for config file path
20+ Console . Write ( "Enter config file path (press Enter for default): " ) ;
21+ string configPath = Console . ReadLine ( ) ;
22+ if ( string . IsNullOrWhiteSpace ( configPath ) )
23+ {
24+ configPath = null ;
25+ Console . WriteLine ( "Using default config file." ) ;
26+ }
27+ else
28+ {
29+ Console . WriteLine ( $ "Using config file: { configPath } ") ;
30+ }
31+ Console . WriteLine ( ) ;
32+
1933 bool exitRequested = false ;
2034
2135 while ( ! exitRequested )
@@ -25,31 +39,68 @@ static void Main(string[] args)
2539 Console . WriteLine ( "2. Decrypt ConnectionStrings section\n 2. ConnectionStrings 섹션 복호화" ) ;
2640 Console . WriteLine ( "3. Encrypt AppSettings section\n 3. AppSettings 섹션 암호화" ) ;
2741 Console . WriteLine ( "4. Decrypt AppSettings section\n 4. AppSettings 섹션 복호화" ) ;
28- Console . WriteLine ( "5. Exit\n 5. 종료" ) ;
29- Console . Write ( "Choice (1-5): 선택 (1-5): " ) ;
42+ Console . WriteLine ( "5. Encrypt only password in a connection string\n 5. 연결 문자열에서 비밀번호만 암호화" ) ;
43+ Console . WriteLine ( "6. Decrypt only password in a connection string\n 6. 연결 문자열에서 비밀번호만 복호화" ) ;
44+ Console . WriteLine ( "7. Exit\n 7. 종료" ) ;
45+ Console . Write ( "Choice (1-7): 선택 (1-7): " ) ;
3046
3147 string choice = Console . ReadLine ( ) ;
3248 Console . WriteLine ( ) ;
3349
50+ // Print config file path before each operation
51+ string pathMsg = configPath == null ? "(default config file)" : configPath ;
52+ Console . WriteLine ( $ "[Config file: { pathMsg } ]") ;
53+
3454 switch ( choice )
3555 {
3656 case "1" :
37- ConfigEncryption . EncryptConnectionStrings ( ) ;
57+ ConfigEncryption . EncryptConnectionStrings ( configPath ) ;
3858 break ;
3959
4060 case "2" :
41- ConfigEncryption . DecryptConnectionStrings ( ) ;
61+ ConfigEncryption . DecryptConnectionStrings ( configPath ) ;
4262 break ;
4363
4464 case "3" :
45- ConfigEncryption . EncryptAppSettings ( ) ;
65+ ConfigEncryption . EncryptAppSettings ( configPath ) ;
4666 break ;
4767
4868 case "4" :
49- ConfigEncryption . DecryptAppSettings ( ) ;
69+ ConfigEncryption . DecryptAppSettings ( configPath ) ;
5070 break ;
5171
5272 case "5" :
73+ Console . Write ( "Enter connection string name: " ) ;
74+ string encName = Console . ReadLine ( ) ;
75+ var encMgr = new ConnectionStringManager ( configPath ) ;
76+ encMgr . EncryptPasswordOnly ( encName ) ;
77+ break ;
78+
79+ case "6" :
80+ Console . Write ( "Enter connection string name: " ) ;
81+ string decName = Console . ReadLine ( ) ;
82+ var decMgr = new ConnectionStringManager ( configPath ) ;
83+ // Decrypt password in connection string and update config
84+ string connStr = System . Configuration . ConfigurationManager . ConnectionStrings [ decName ] ? . ConnectionString ;
85+ if ( string . IsNullOrEmpty ( connStr ) )
86+ {
87+ Console . WriteLine ( $ "Cannot find connection string '{ decName } '.\n 연결 문자열 '{ decName } '을 찾을 수 없습니다.") ;
88+ }
89+ else if ( ! connStr . Contains ( "Password=ENC:" ) )
90+ {
91+ Console . WriteLine ( "No encrypted password found in the connection string.\n 연결 문자열에 암호화된 비밀번호가 없습니다." ) ;
92+ }
93+ else
94+ {
95+ string decrypted = CustomEncryption . DecryptPasswordInConnectionString ( connStr ) ;
96+ // Update config file with decrypted password
97+ decMgr . GetType ( ) . GetMethod ( "UpdateConnectionStringInConfigFile" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Instance )
98+ . Invoke ( decMgr , new object [ ] { decName , decrypted } ) ;
99+ Console . WriteLine ( $ "Password in connection string '{ decName } ' has been decrypted.\n 연결 문자열 '{ decName } '의 비밀번호가 복호화되었습니다.") ;
100+ }
101+ break ;
102+
103+ case "7" :
53104 exitRequested = true ;
54105 break ;
55106
0 commit comments