http://www.hanbit.co.kr/store/books/look.php?p_code=B6910482773

 

오준석의 안드로이드 생존코딩(코틀린 편)

이 책은 기본을 빠르게 익히고 나서 현업에서 사용하는 라이브러리와 프레임워크로 앱을 효과적으로 만드는 방법을 알려주는 입문 + 활용서입니다. 코틀린을 몰라도, 안드로이드를 몰라도 안드로이드 앱을 만들 수 있습니다. ‘코틀린 입문 + 안드로이드 SDK 입문 + 실전 앱 개발’을 한 권으로 전달하니까요.

www.hanbit.co.kr

코틀린을 공부히가 위해 참고했던 책입니다.

 

9 가지에 예제를 만들어 가며 코틀린에 대한 개념을 익힐 수 있었습니다.

 

다만, 기본적인 내용이 대부분이라, 쓰레드 안정성이랄지, API 함수의 내부 동작 방식이라던지 깊이있는 부분은 따로 찾아서 공부해야 합니다. 

 

예제가 참 맘에 들어서 재미있게 따라했는데, Xamarin 으로 똑같은 예제를 만들어 보면 Xamarin 공부하는데 좋겠다는 생각이 들었습니다. 

 

최근 바쁜일도 없으니 시간이 될때 마다 만들어 보겠습니다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.common.test;
 
import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
 
import javax.crypto.Cipher;
 
public class RsaSample {
 
    public static String ByteArrayToHexString(byte[] ba) {
        if (ba == null || ba.length == 0) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (final byte b : ba) {
            sb.append(String.format("%02X", b & 0xff));
        }
        
        return sb.toString().substring(0, sb.toString().length()).toUpperCase();
    }
 
    public static void main(String[] args) {
        
        try {
            
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
            //keyPairGenerator.initialize(1024);
            //String plain = String.format("%117s", "TEST MESSAGE");
            
            //keyPairGenerator.initialize(2048);
            //String plain = String.format("%245s", "TEST MESSAGE");
            
            keyPairGenerator.initialize(4096);
            String plain = String.format("%501s""TEST MESSAGE");
            
            KeyPair keyPair = keyPairGenerator.generateKeyPair();
            
            RSAPublicKey pub = (RSAPublicKey) keyPair.getPublic(); 
            RSAPrivateKey pvt = (RSAPrivateKey) keyPair.getPrivate();
            
            System.out.println(pub);
            System.out.println(pvt);
            
            BigInteger biModulus = pub.getModulus();
            BigInteger biExponent = pub.getPublicExponent();
            
            BigInteger biPrivateExponent = pvt.getPrivateExponent();
            
            byte [] bModulus = biModulus.toByteArray();
            String strModulus = ByteArrayToHexString(bModulus);
 
            byte [] bExponent = biExponent.toByteArray();
            String strExponent = ByteArrayToHexString(bExponent);
 
            byte [] bPrivateExponent = biPrivateExponent.toByteArray();
            String strPrivateExonent = ByteArrayToHexString(bPrivateExponent);
            
            System.out.printf("Modulus: [%s]\n", strModulus);
            System.out.printf("Exponent: [%s]\n", strExponent);
            System.out.printf("Private Exponent: [%s]\n", strPrivateExonent);
            
            BigInteger modulus = new BigInteger(strModulus, 16);
            BigInteger exponent = new BigInteger(strExponent, 16);
            BigInteger privateExponent = new BigInteger(strPrivateExonent, 16);
    
            byte[] encrypted = null;
            byte[] decrypted = null;
        
            PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(modulus, exponent));
            PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(new RSAPrivateKeySpec(modulus, privateExponent));
 
            System.out.println(publicKey);
            System.out.println(privateKey);
 
            //RSA/ECB/PKCS1Padding (1024, 2048)
            //RSA/ECB/OAEPWithSHA-1AndMGF1Padding (1024, 2048)
            //RSA/ECB/OAEPWithSHA-256AndMGF1Padding (1024, 2048)
            Cipher encCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            encCipher.init(Cipher.ENCRYPT_MODE, publicKey);
            
            System.out.printf("Plain Data: [%s]\n", plain);
            
            encrypted = encCipher.doFinal(plain.getBytes());
            
            Cipher decCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            decCipher.init(Cipher.DECRYPT_MODE, privateKey);
            decrypted = decCipher.doFinal(encrypted);
            
            String hexEncrypted = ByteArrayToHexString(encrypted);
            System.out.printf("Encrypted Data: [%s]\n", hexEncrypted);
            
            String strDecrypted = new String(decrypted);
            System.out.printf("Decrypted Data: [%s]\n", strDecrypted);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.common.test;
 
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
 
public class QueueTest {
    
    static final int MAX_SIZE = 1000;
    static Queue<String> queue = new LinkedBlockingQueue<String>(MAX_SIZE);
    
    static final int THREAD_COUNT = 500;
    
    static class addThread implements Runnable {
        
        String strParameter = null;
        
        addThread(String parameter){
            strParameter = parameter;
        }
        
        public void run() {
            try {
                while(true) {
                    if(queue.size() < MAX_SIZE) {
                        queue.offer(strParameter);
                        System.out.printf("offer %s, size %d\n", strParameter, queue.size());
                    }
                    Thread.sleep(10);
                }
            } catch(Exception ex) {
                ex.printStackTrace();
            }    
        }
    }
    
    static class removeThread implements Runnable {
        
        public void run() {
            try {
                while(true) {
                    if(!queue.isEmpty()) {
                        System.out.printf("poll %s, size %d\n", queue.poll(), queue.size());
                    }
                    Thread.sleep(10);
                }
            } catch(Exception ex) {
                ex.printStackTrace();
            }
        }
    }
        
    public static void main(String[] args) {
        try {
            
            for(int i = 0; i < THREAD_COUNT; i++) {
                Runnable runnable = new addThread(i + "");
                Thread thread = new Thread(runnable);
                thread.start();
            }
            
            for(int i = 0; i < THREAD_COUNT; i++) {
                Runnable runnable = new removeThread();
                Thread thread = new Thread(runnable);
                thread.start();
            }
            
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
 
}
 
cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package com.common.test;
 
import java.security.MessageDigest;
 
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
 
public class CryptoTest {
 
    private static String strPlain = "Test Message";
    
    /**
     * Convert byte array to hexadecimal
     *
     * @param buffer
     *            Buffer with bytes
     * @return String with hexadecimal data
     */
    public static String ByteArrayToHexString(byte[] ba) {
        return ByteArrayToHexString(ba, "");
    }
 
    public static String ByteArrayToHexString(byte[] ba, String split) {
        if (ba == null || ba.length == 0) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (final byte b : ba) {
            sb.append(String.format("%02X", b & 0xff));
            sb.append(split);
        }
        return sb.toString().substring(0, sb.toString().length()).toUpperCase();
    }
 
    /**
     * Convert hexadecimal string to byte array
     *
     * @param String
     *            with hexadecimal data
     * @return byte array
     */
    public static byte[] HexStringToByteArray(String hex) {
 
        if (hex == null || hex.length() == 0) {
            return null;
        }
 
        byte[] ba = new byte[hex.length() / 2];
 
        for (int i = 0; i < ba.length; i++) {
 
            ba[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16);
        }
 
        return ba;
    }
    
    /* AES START -------------------------------------------------------------------------------- */
    
    private static byte [] aesEncrypt(byte [] key, byte [] plain, IvParameterSpec iv) {
        byte [] result = null;
        try {
            Cipher encCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            SecretKeySpec encSecretKey = new SecretKeySpec(key, 0, key.length"AES");
            
            encCipher.init(Cipher.ENCRYPT_MODE,  encSecretKey, iv);
            result = encCipher.doFinal(plain);
        } catch(Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }
    
    private static byte [] aesDecrypt(byte [] key, byte [] plain, IvParameterSpec iv) {
        byte [] result = null;
        try {
            Cipher decCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            SecretKeySpec encSecretKey = new SecretKeySpec(key, 0, key.length"AES");
            
            decCipher.init(Cipher.DECRYPT_MODE,  encSecretKey, iv);
            result = decCipher.doFinal(plain);
        } catch(Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }
    
    private static void AesTest() {
        try {
            //byte [] key = new byte[16];
            //byte [] key = new byte[24];
            byte [] key = new byte[24];
            byte [] byteAesIv = new byte[16];
            byte [] encrypted = null;
            String hexEncrypted = null;
            byte [] decrypted = null;
            byte [] plain = strPlain.getBytes();
            String strResult = null;
            
            IvParameterSpec aesIv = new IvParameterSpec(byteAesIv);
            
            encrypted = aesEncrypt(key, plain, aesIv);
            hexEncrypted = ByteArrayToHexString(encrypted);
            System.out.println(hexEncrypted);
            
            decrypted = aesDecrypt(key, encrypted, aesIv);
            strResult = new String(decrypted);
            System.out.println(strResult);
            
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    
    /* AES END -------------------------------------------------------------------------------- */
    
    /* DESede START -------------------------------------------------------------------------------- */
    
    private static byte [] desEdeEncrypt(byte [] key, byte [] plain, IvParameterSpec iv) {
        byte [] result = null;
        try {
            Cipher encCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
            SecretKeySpec encSecretKey = new SecretKeySpec(key, 0, key.length"DESede");
            
            encCipher.init(Cipher.ENCRYPT_MODE,  encSecretKey, iv);
            result = encCipher.doFinal(plain);
        } catch(Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }
    
    private static byte [] desEdeDecrypt(byte [] key, byte [] plain, IvParameterSpec iv) {
        byte [] result = null;
        try {
            Cipher decCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
            SecretKeySpec encSecretKey = new SecretKeySpec(key, 0, key.length"DESede");
            
            decCipher.init(Cipher.DECRYPT_MODE,  encSecretKey, iv);
            result = decCipher.doFinal(plain);
        } catch(Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }
    
    private static void DesEdeTest() {
        try {
            byte [] key = new byte[24];
            byte [] byteDesEdeIv = new byte[8];
            byte [] encrypted = null;
            String hexEncrypted = null;
            byte [] decrypted = null;
            byte [] plain = strPlain.getBytes();
            String strResult = null;
            
            IvParameterSpec desEdeIv = new IvParameterSpec(byteDesEdeIv);
            
            encrypted = desEdeEncrypt(key, plain, desEdeIv);
            hexEncrypted = ByteArrayToHexString(encrypted);
            System.out.println(hexEncrypted);
            
            decrypted = desEdeDecrypt(key, encrypted, desEdeIv);
            strResult = new String(decrypted);
            System.out.println(strResult);
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    
    /* DESede END -------------------------------------------------------------------------------- */
    
    private static void HashTest() {
        try {
            // MD2, MD5
            // SHA-1, SHA-256, SHA-384, SHA-512
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.update(strPlain.getBytes());
            
            byte [] byteDigest = md.digest();
            String hexDigest = ByteArrayToHexString(byteDigest);
            System.out.println(hexDigest);
            
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    
    private static void HmacTest() {
        try {
            byte [] hmacKey = new byte[16];
            SecretKeySpec macSecretKey = new SecretKeySpec(hmacKey, 0, hmacKey.length"HmacSHA256");
            Mac mac = Mac.getInstance("HmacSHA256");
            
            mac.init(macSecretKey);
            mac.update(strPlain.getBytes());
            byte [] byteMac = mac.doFinal();
            
            String hexDigest = ByteArrayToHexString(byteMac);
            System.out.println(hexDigest);
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        try {
            AesTest();
            
            DesEdeTest();
            
            HashTest();
            
            HmacTest();
            
        } catch(Exception ex) {
            ex.printStackTrace();
        }
 
    }
 
}
 
cs

Check


<beans:beans

xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:beans="http://www.springframework.org/schema/beans"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:p="http://www.springframework.org/schema/p"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="

http://www.springframework.org/schema/beans 

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context 

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/util 

http://www.springframework.org/schema/util/spring-util-3.0.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx.xsd"

>




출처: http://lynlab.co.kr/blog/41/


파일 수정: C:\Program Files\Android\Android Studio\plugins\android\lib\layoutlib\data\fonts\fonts.xml 


원본

<family lang="ko">

        <font weight="400" style="normal" index="1">NotoSansCJK-Regular.ttc</font>

</family>


수정본

<family lang="ko">

        <font weight="400" style="normal" index="1">NanumGothic.ttf</font>

</family>


폰트 명은 취향대로 선택.

+ Recent posts