티스토리 뷰
public static String encodeBase64(String s) {
return Base64.getEncoder().encodeToString(s.getBytes());
}
public static String decodeBase64(String s) {
try {
if (isBase64(s)) {
return new String(Base64.getDecoder().decode(s));
} else {
return s;
}
} catch (Exception e) {
return s;
}
}
public static boolean isBase64(String s) {
String pattern = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(s);
return m.find();
}
How to check whether a string is Base64 encoded or not
I want to decode a Base64 encoded string, then store it in my database. If the input is not Base64 encoded, I need to throw an error. How can I check if a string is Base64 encoded?
stackoverflow.com
https://www.baeldung.com/java-base64-encode-and-decode
https://dev-syhy.tistory.com/15
[Java] base64 인코딩 디코딩 (encoding / decoding)
일단 인코딩, 디코딩을 쉽게 설명을 하면 "hello world" 라는 단어를 인코딩을 하면 base64형태로 인코딩 됩니다. base64를 디코딩하면 "hello world"라고 나오게 되는 것이죠 자바 버전별로 사용되는게 너
dev-syhy.tistory.com
https://stackoverflow.com/questions/8571501/how-to-check-whether-a-string-is-base64-encoded-or-not
How to check whether a string is Base64 encoded or not
I want to decode a Base64 encoded string, then store it in my database. If the input is not Base64 encoded, I need to throw an error. How can I check if a string is Base64 encoded?
stackoverflow.com
'공부' 카테고리의 다른 글
[Java] reverse String (0) | 2021.12.07 |
---|---|
[Shell] `echo 'test' | base64`; `echo 'dGVzdAo=' | base64 --decode` (0) | 2021.12.07 |
[JavaScript] remove tags (0) | 2021.11.29 |
[Linux] download wget `url` (0) | 2021.11.28 |
[JavaScript] request XMLHttpRequest (promise & async ~ await) (0) | 2021.11.28 |
- Total
- Today
- Yesterday
- 개리마커스
- 어떻게 능력을 보여줄 것인가?
- 테슬라 리퍼럴 코드
- 모델 Y 레퍼럴
- 김달
- 테슬라 추천
- 클루지
- 유투브
- 테슬라 레퍼럴 적용 확인
- COUNT
- 테슬라 레퍼럴 코드 확인
- 모델y
- 테슬라
- 테슬라 리퍼럴 코드 생성
- 연애학개론
- follower
- 테슬라 레퍼럴
- 테슬라 리퍼럴 코드 혜택
- wlw
- 인스타그램
- Bot
- Kluge
- 할인
- 팔로워 수 세기
- 책그림
- 테슬라 크레딧 사용
- 레퍼럴
- 메디파크 내과 전문의 의학박사 김영수
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |