- λ°μ΄ν°λ₯Ό νλ¬ΈμΌλ‘ ν΅μ μ±λμ ν΅ν΄ μ‘μμ ν κ²½μ°, μΈμ¦λ°μ§ μμ μ¬μ©μμ μν΄ λ°μν
μ€λν
μ ν΅ν΄ 보μκ³Ό κ΄λ ¨λ μ€μν λ°μ΄ν°κ° λ ΈμΆλ μ μλ€.μ€λν
: λ€νΈμν¬μμμ λ€λ₯Έ μλλ°©λ€μ ν¨ν· κ΅νμ μΏλ£λ νμ. ex) μ ν λμ²
- μ€μν μ 보λ₯Ό μ μ₯ν λμλ λ°λμ
μνΈν
νμ¬ μ μ₯νλ€. - μ€μν μ 보λ₯Ό ν΅μ μ±λμ ν΅ν΄ μ μ‘ν λμλ λ°λμ
μνΈν
κ³Όμ μ κ±°μ³μΌ νλ€.- νμν κ²½μ° SSL λλ HTTPSμ κ°μ 보μ μ±λμ μ¬μ©νλ€.
- 보μ μ±λμ μ¬μ©νκ±°λ λΈλΌμ°μ μΏ ν€μ μ€μ λ°μ΄ν°λ₯Ό μ μ₯νλ κ²½μ°,
setSecure(true)
λ©μλλ₯Ό ν΅ν΄ μΏ ν€ κ°μ²΄μ 보μμμ±μ μ€μ νμ¬ μ€μμ 보 λ ΈμΆμ λ°©μ§ν μ μλ€. - 보μμμ±μ΄ μ€μ λ μΏ ν€λ HTTPλ‘λ μ μ‘λμ§ μμΌλ―λ‘, μ€μ λ°μ΄ν°λ₯Ό μ μ₯ν μΏ ν€λ₯Ό HTTPλ‘ μ μ‘νκΈ° μν΄μλ 보μ μμ±μ λμ νμ¬ λ°λμ μνΈνλ₯Ό μ μ©ν΄μΌ νλ€.
String password = getPassword();
o.write(password);
ν¨μ€μλλ₯Ό μνΈννμ§ μκ³ νλ¬ΈμΌλ‘ μ μ‘νκ³ μλ€. μ΄ κ²½μ°μ ν¨ν· μ€λνμ ν΅ν΄ ν¨μ€μλκ° λ ΈμΆλ μ μλ€.
μμ νμ§ μμ μ½λ
try {
Socket s = new Socket("taranis", 4444);
PrintWriter o = new PrintWriter(s.getOutputStream(), true);
String password = getPassword();
o.write(password);
} catch (FileNotFoundException e) {
β¦β¦
Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
String password = getPassword();
byte[] encPassword = c.update(password.getBytes());
ν¨μ€μλλ₯Ό λ€νΈμν¬λ₯Ό ν΅ν΄ μλ²λ‘ μ μ‘νκΈ° μ μ μνΈννμ¬ μμ ν νλ‘κ·Έλ¨μ΄λ€. μ΄ μμ λ AES μνΈν μκ³ λ¦¬μ¦μ μ¬μ©νμλ€.
μμ ν μ½λ
try {
Socket s = new Socket("taranis", 4444);
PrintStream o = new PrintStream(s.getOutputStream(), true);
Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
String password = getPassword();
byte[] encPassword = c.update(password.getBytes());
o.write(encPassword, 0, encPassword.length);
} catch (FileNotFoundException e) {
β¦β¦
Socket socket = new Socket(hostname, port);
μΌλ°μ μΈ μμΌ ν΅μ μ μ¬μ©νμ¬ λ€νΈμν¬λ₯Ό ν΅νμ¬ λ°μ΄ν°λ₯Ό μΈλΆμ μ μ‘νκ³ μλ€. λ§μ°¬κ°μ§λ‘ μ΄ κ²½μ°λ ν¨ν· μ€λνμ ν΅νμ¬ λ°μ΄ν°μ λ΄μ©μ΄ λ ΈμΆλ μ μλ€.
μμ νμ§ μμ μ½λ
public void onCreate(Bundle savedInstanceState) {
int port = 443;
String hostname = "hostname";
Socket socket = new Socket(hostname, port);
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
// Read from in and write to out...
inclose();
out.close();
}
SocketFactory socketFactory = SSLSocketFactory.getDefault();
Socket socket = socketFactory.createSocket(hostname, port);
λ―Όκ°ν μ 보λ₯Ό λ€νΈμν¬λ₯Ό ν΅νμ¬ μλ²μ μ μ‘νκΈ° μ μ μ΅μν 128λΉνΈ κΈΈμ΄μ ν€λ₯Ό μ΄μ©νμ¬ μνΈννλ κ²μ΄ λ°λμ§νλ€.
μμ ν μ½λ
public void onCreate(Bundle savedInstanceState) {
int port = 443;
String hostname = "hostname";
SocketFactory socketFactory = SSLSocketFactory.getDefault();
Socket socket = socketFactory.createSocket(hostname, port);
InputStream in = socket.getInputStream();
OutputStream out = socket.getOuputStream();
// Read from in and write to out..
in.close();
out.close();
}
νμΌμμ μ½μ ν¨μ€μλ μνΈν μμ΄ μ§μ μ°κ²° β‘ ν¨μ€μλ κ²μ¦ (AES-CBC μνΈν)
fgets(passwd, sizeof(passwd), fp);
ν¨μ€μλλ₯Ό νμΌμμ μ½μ΄ μ€κ³ μλ€.
(SQLCHAR*) passwd,
νμΌμμ μ½μ΄μ¨ ν¨μ€μλλ₯Ό μνΈν μμ΄ μ§μ μ°κ²°νκ³ μλ€.
μμ νμ§ μμ μ½λ
int dbaccess(){
FILE *fp; char *server = "DBserver";
char passwd[20];
char user[20];
SQLHENV henv;
SQLHDBC hdbc;
fp = fopen("config", "r");
fgets(user, sizeof(user), fp);
fgets(passwd, sizeof(passwd), fp);
fclose(fp);
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
SQLConnect(hdbc,
(SQLCHAR*) server,
(SQLSMALLINT) strlen(server),
(SQLCHAR*) user,
(SQLSMALLINT) strlen(user),
(SQLCHAR*) passwd,
(SQLSMALLINT) strlen(passwd) );
return 0;
}
μΈλΆμμ μ λ ₯λ ν¨μ€μλλ κ²μ¦μ κ³Όμ μ κ±°μ³μ μ¬μ©ν΄μΌ νλ€.
char *key;
HCkCrypt2 crypt = CkCrypt2_putCryptAlgorithm(crypt,βaesβ);
CkCrypt2_putCipherMode(crypt,βcbcβ);
AES-CBCλ‘ μνΈν λͺ¨λλ₯Ό μ€μ νλ€.
key = getenv(βencrypt_keyβ);
CkCrypt2_SetEncodedKey(crypt,key,βhexβ);
μΈλΆμμ μνΈν ν€λ₯Ό λΆλ¬μ μ€μ νλ€.
fgets(passwd, sizeof(passwd), fp);
ν¨μ€μλλ₯Ό νμΌμμ μ½μ΄μ¨λ€.
encPasswd = CkCrypt2_encryptStringENC(crypt, passwd);
ν¨μ€μλ μνΈνλ₯Ό μ§ννλ€.
(SQLCHAR*) encPasswd,
μνΈνλ ν¨μ€μλλ₯Ό μ¬μ©νλ€.
μμ ν μ½λ
int dbaccess(){
FILE *fp; char *server = "DBserver";
char passwd[20];
char user[20];
char *encPasswd;
char *key;
SQLHENV henv;
SQLHDBC hdbc;
HCkCrypt2 crypt = CkCrypt2_putCryptAlgorithm(crypt,βaesβ);
CkCrypt2_putCipherMode(crypt,βcbcβ);
key = getenv(βencrypt_keyβ);
CkCrypt2_SetEncodedKey(crypt,key,βhexβ);
fp = fopen("config", "r");
fgets(user, sizeof(user), fp);
fgets(passwd, sizeof(passwd), fp);
fclose(fp);
encPasswd = CkCrypt2_encryptStringENC(crypt, passwd);
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
SQLConnect(hdbc,
(SQLCHAR*) server,
(SQLSMALLINT) strlen(server),
(SQLCHAR*) user,
(SQLSMALLINT) strlen(user),
(SQLCHAR*) encPasswd,
(SQLSMALLINT) strlen(verifiedPwd) );
return 0;
}
Message.Body = "Your password is: " + Server.HtmlEncode(password);
SmtpMail.Send(Message);
ν¨μ€μλλ₯Ό μνΈννμ§ μκ³ ν¨μ€μλκ° ν¬ν¨λ λ©μμ§λ₯Ό λ€νΈμν¬λ₯Ό ν΅νμ¬ μ μ‘νκ³ μλ€. μ΄ κ²½μ° λν ν¨ν·μ€λνμ ν΅νμ¬ ν¨μ€μλκ° λ ΈμΆλ μ μλ€.
μμ νμ§ μμ μ½λ
public void EmailPassword_OnClick(object sender, EventArgs args)
{
MembershipUser u = Membership.GetUser(UsernameTextBox.Text, false);
String password;
if (u != null)
{
try
{
password = u.GetPassword(); // sensitive data created
}
catch (Exception e)
{
Msg.Text = "An exception occurred retrieving your password: " +
Server.HtmlEncode(e.Message);
return;
}
MailMessage Message = new MailMessage();
Message.Body = "Your password is: " + Server.HtmlEncode(password);
SmtpMail.Send(Message);
Msg.Text = "Password sent via e-mail.";
}
else
{
Msg.Text = "User name is not valid. Please check the value and try again.";
}
}
byte[] data = System.Text.Encoding.ASCII.GetBytes(password);
data = new
System.Security.Cryptography.SHA256Managed().ComputeHash(data);
String hashedPassword = System.Text.Encoding.ASCII.GetString(data);
ν¨μ€μλλ₯Ό μνΈννμ¬ λ€νΈμν¬λ₯Ό ν΅ν΄ μ μ‘νλ€.
μμ ν μ½λ
public void EmailPassword_OnClick(object sender, EventArgs args)
{
MembershipUser u = Membership.GetUser(UsernameTextBox.Text, false);
String password;
if (u != null)
{
try
{
password = u.GetPassword();
byte[] data = System.Text.Encoding.ASCII.GetBytes(password);
data = new
System.Security.Cryptography.SHA256Managed().ComputeHash(data);
String hashedPassword = System.Text.Encoding.ASCII.GetString(data);
}
catch (Exception e)
{
Msg.Text = "An exception occurred retrieving your password: " +
Server.HtmlEncode(e.Message);
return;
}
MailMessage Message = new MailMessage();
Message.Body = "Your password is: " + Server.HtmlEncode(hasedPassword);
SmtpMail.Send(Message);
Msg.Text = "Password sent via e-mail.";
}
else
{
Msg.Text = "User name is not valid. Please check the value and try again.";
}
}