LANGUAGE/!$%!% ERROR NOTE 2017. 11. 1. 21:00

!markdown

# Base64


### 1. Warning (경고)


sun.mice를 사용하면 컴파일(빌드)시, 다음 경고메세지가 발생한다. 


```log

warning: BASE64Decoder is internal proprietary API and may be removed in a future release

import sun.misc.BASE64Decoder;


 warning: BASE64Encoder is internal proprietary API and may be removed in a future release

import sun.misc.BASE64Encoder;

```




### 2. Problem (문제)


차기버전에서 없어질지 모르는 기능이므로 사용을 자제해달라는 것인데

컴파일이 된다면, 딱히 문제는 없지만 매번 메세지가 발생하면 지저분해지고 자꾸 신경쓰인다.




### 3. Solved (해결)


sun.mice의 Base64를 지양하고 `기본 API의 Base64` 또는 `Apache의 Base64`를 사용할 수 있다.


#### 1) sun.mice


```java

String originalContent = "Test Base64"

byte[] base64 = new BASE64Encoder().encode(originalContent);

assert originalContent == new BASE64Decoder().decodeBuffer(base64);

```


#### 2) JDK6+ 


```java

String originalContent = "Test Base64"

byte[] baee64 = DatatypeConverter.parseBase64Binary(originalContent);

assert originalContent == DatatypeConverter.printBase64Binary(baee64);

```


#### 3) Apache


```java

String originalContent = "Test Base64";

byte[] baee64 = Base64.encodeBase64String(originalContent);

assert originalContent == Base64.decodeBase64(base64EncryptedContent);

```


아파치를 사용한다면, 아래의 의존성 라이브러리가 필요하다. 


- Maven이라면

```xml

<dependency>

    <groupId>commons-codec</groupId>

    <artifactId>commons-codec</artifactId>

    <version>1.11</version>

</dependency>

```


- Gradle이라면

```groovy

compile group: 'commons-codec', name: 'commons-codec', version: '1.11'

```




### 4. Reference (참고)


- how to avoid warning for the Base 64?: [https://stackoverflow.com/questions/21904682/how-to-avoid-warning-for-the-base-64](https://stackoverflow.com/questions/21904682/how-to-avoid-warning-for-the-base-64)


- Base64 Java encode and decode a string [duplicate]: [https://stackoverflow.com/questions/19743851/base64-java-encode-and-decode-a-string](https://stackoverflow.com/questions/19743851/base64-java-encode-and-decode-a-string)

- Apache Commons Codec » 1.11: [https://mvnrepository.com/artifact/commons-codec/commons-codec/1.11](https://mvnrepository.com/artifact/commons-codec/commons-codec/1.11)