4월, 2019의 게시물 표시

Spring Boot Scheduler

서버를 개발하다보면 데몬 형태로 주기적인 업무 처리가 필요 할 때가 있다. 그럴때 Spring Boot의 Scheduler를 사용하면 손쉽게 처리가 가능 하다. 필요한 annotation 1. @EnableScheduling: background task executor가 생성된다. 2. @Scheduled: 실제 scheduling task를 실행할 녀석들. example) 1. main문에 @EnableScheduling 추가 @SpringBootApplication @EnableScheduling public class Application { public static void main ( String [] args ) { SpringApplication . run ( Application . class ); } /* 1. task in current thread */ @Bean public TaskScheduler taskScheduler () { return new ConcurrentTaskScheduler (); } /* 2. multi thread */ @Bean public TaskScheduler taskScheduler () { ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler (); taskScheduler . setPoolSize ( 10 ); return taskScheduler ; } } 설명) - @EnableScheduling이 명시되면 정해진 일정대로 ScheduledThreadPoolExecutor에 의해 관리되는 Worker thread를 실행하여 스케쥴 작업을 처리 한다. - 스케쥴을 관리할 org.spri

Java SHA256WithECDSA Output Format

Java JCE는  ASN.1 DER  인코딩 포멧을 사용한다. 예를 들어 설명하면, 3044022059eb9bc695d7f7d64f9632c3ae684a022660049e8b05cd67f32a19d120abe68a02203bac6d491a57b7f70c33c2e31e0b02b7f55ee71310ce217ad54144e30df4b106 앞 0x30은 SEQUENCE tag.(실제는 SEQUENCE 0x10 + 0x20'constructed') 그 뒤는 body sequence의 길이. 0x02는 INTEGER이며 그뒤는 첫번째 integer의 길이. 그 길이만큼이 point 값이며 다시 0x02 나오는 부분이 INEGER이며 그 뒤는 point 값 길이. 위 예제에서 처음 0x02를 찾고, 3044 02 2059eb9bc695d7f7d64f9632c3ae684a022660049e8b05cd67f32a19d120abe68a 02 203bac6d491a57b7f70c33c2e31e0b02b7f55ee71310ce217ad54144e30df4b106 그 뒤 0x20 = 32byte 데이터 304402 20 59eb9bc695d7f7d64f9632c3ae684a022660049e8b05cd67f32a19d120abe68a02 20 3bac6d491a57b7f70c33c2e31e0b02b7f55ee71310ce217ad54144e30df4b106 그러므로 아래처럼 32byte 데이터 두개 30440220 59eb9bc695d7f7d64f9632c3ae684a022660049e8b05cd67f32a19d120abe68a 0220 3bac6d491a57b7f70c33c2e31e0b02b7f55ee71310ce217ad54144e30df4b106 signature에서 데이터를 뽑아야 할 필요가 있을때 유용하게 사용할듯~ 출처:  https://stackoverflow.com/questions/48530316/

Java BigInteger 0x00 Trim

BigInteger.toByteArray()를 하면 최상위 비트가 1일때는 앞에 0x00이 붙게 된다. 아래  Java Doc BigInteger  참고. The array will contain the minimum number of bytes required to represent this BigInteger, including at least one sign bit, which is  (ceil((this.bitLength() + 1)/8)) .  어떤 이유로 이 0x00을 잘라서 사용해야 할 때가 있다. 아래 코드로 trim 해보자. private byte [] trimMostSignificantZero ( byte [] bytes ) { if ( bytes [ 0 ] == 0 ) { byte [] trimed = new byte [ bytes . length - 1 ]; System . arraycopy ( bytes , 1 , trimed , 0 , trimed . length ); return trimed ; } return bytes ; }

JavaScript Tip 모음

Deep Copy function _clone(o) {     return JSON.parse(JSON.stringify(o)); }

[Java] AES128 vs AES256

이미지
코드를 작성할때의 AES256과 AES128의 차이는 KeySpec 생성 시 key 길이를 256bit(32byte) 혹은 128bit(16byte)를 사용하느냐의 차이. Initial Vector는 둘다 모두 128bit(16byte) 사용. 아래 코드는 CBC(Cipher Block Chaining)와 PKCS5 패딩을 사용하는 구현. Encrypt final static String key = "key입력하는 하세요" ; public String encrypt ( String str ) throws NoSuchAlgorithmException , GeneralSecurityException , UnsupportedEncodingException { String ivStr = key . substring ( 0 , 16 ); // Set key spec & initial vector spec SecretKeySpec keySpec = new SecretKeySpec ( key . getBytes ( CharEncoding . UTF_8 ), "AES" ); IvParameterSpec ivSpec = new IvParameterSpec ( ivStr . getBytes ( CharEncoding . UTF_8 )); // Set cipher of CBC & PKCS5 Cipher cipher = Cipher . getInstance ( "AES/CBC/PKCS5Padd

[Java] String을 Hex 값으로 표현하기

아래 코드로 String 문자열을 Hex 문자열로 바꿀 수 있다. public String stringToHex ( String s ) { StringBuilder sb = new StringBuilder (); for ( int i = 0 ; i < s . length (); i ++) { sb . append ( String . format ( "%02X" , ( int ) s . charAt ( i ))); } return sb . toString (); }

[JPA] Spring Boot MariaDB 설정

1. configuration spring:     datasource:         url: jdbc:mysql://127.0.0.1:3306/yourDbName         username: root         password: root         driver-class-name: org.mariadb.jdbc.Driver     jpa:         properties:             hibernate:                 dialect: org.hibernate.dialect.MariaDB53Dialect 주의) hibernate.dialect 반드시 셋팅 되어야 함. driver-class-name 반드시 셋팅 되어야 함. dialect는 여러가지 있음.  https://planet.jboss.org/post/mariadb_dialects 참조 2. Maven POM <dependency>     <groupId>org.mariadb.jdbc</groupId>     <artifactId>mariadb-java-client</artifactId>     <version>1.1.9</version> </dependency> <!-- if not already present --> <dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>

[Database] MySQL utf8 과 utf8mb4

이미지
MySQL character set에 대해 좋은 자료가 있어 링크 함. 출처:  https://blog.lael.be/post/917 [MySQL/MariaDB] utf8mb4 언어셋 소개 및 표현범위. 기술이 매우 빠르게 발전한다. 배워도 배워도 계속 배워야 한다. 최근에 라엘이가 앞으로 100년동안은 나타나지 않을 것이라고 예상했던, 4 Byte UTF-8 문자열을 보고  여러 깨닳은 바가 있었고 여러분에게 도움이 될만한 정보가 있어 공유하려고 한다. 데이터베이스를 구축하다보면 텍스트 데이터(Text Data)를 취급해야 할 때가 있다. 이때 반드시 고민해야 하는 것이 있는데, 바로 문자셋(character set)을 선택하는 것이다. 핵심 단어의 뜻 먼저 중요한 두 단어  Charset  과  Collation  의 뜻에 대해서 알고 가자. 구글 번역기를 이용하여 단어 자체의 뜻을 알아보자. charset  은  문자 집합 ,  collation  은  정렬 을 뜻한다. 자료형이 왜 필요하나? 먼저 자료형이 왜 필요할지부터 생각해보자. 컴퓨터 프로그램 은 프로그래머가 의도한 대로 동작한다. 이 때  같은 목적의 프로그램이라고 할지라도  효율적으로 동작하는 것이  더 좋은 프로그램 이 된다. “ 컴퓨터 알고리즘(Computer Algorithm) ” 학문에서는 이를 평가(Performance Analysis)하기 위해서, “ 시간복잡도(time complexity) “와 “ 공간복잡도(space complexity) “의 개념을 사용한다. (참고로 이것을 평가하는 대회가 [ ACM-ICPC ; International Collegiate Programming Contest ; 대학생알고리즘대회 ] 이다. 라엘이도 두번정도 참가해보았으며 컴퓨터 알고리즘의 중요성을 알 수 있게 된다. 관련글 :  https://blog.lael.be/post/136