[질문] 이런 쉘명령어를 아시나요? urlencode base64encode

nonots의 이미지

php jsp 등의 웹프로그래밍 언어에서는 기본이지만..
..
이런 baes64_encode 나 urlencode 등을 리눅스 쉘에서 문자열 변환에
사용하려니까 모르겠군요..
perl awk 같은 .. 기본 설치 리눅스 서버들에게서 공통으로 사용될 수 있는
간단한 명령어나 혹은 응용 방법이 있을까요?
.
실제 필요한 건 복호화가 가능한 문자열 암호화입니다.
인코딩을 이용해서 이런 간단한 암호화 비슷하게 구현해서
좀 민감한 데이타를 보호하려고 합니다.
..
좋은 방법이 없을까요?

bushi의 이미지

[bushi@rose kernel-2.0.40]$ rpm -qf `which base64`
coreutils-6.9-18.fc8
[bushi@rose kernel-2.0.40]$ rpm -qf `which uuencode`
sharutils-4.6.3-1.fc7
[bushi@rose kernel-2.0.40]$ rpm -qf `which uudecode`
sharutils-4.6.3-1.fc7
[bushi@rose kernel-2.0.40]$ rpm -qf `which shar`
sharutils-4.6.3-1.fc7
[bushi@rose kernel-2.0.40]$ rpm -qf `which unshar`
sharutils-4.6.3-1.fc7
[bushi@rose kernel-2.0.40]$ 

base64 가 coreutils 에 들어간게 언제부턴지는 모르겠습니다.
원래는 독립된 패키지 였습니다.
다른 배포본들도 마찬가지라면, 최소한 base64 정돈 모든 리눅스 시스템에 다 있을거라 생각하셔도 됩니다.

uuencode 가 언제부터 shar 에 포함되었는지는 모르겠습니다.
원래는 독립된 패키지 였습니다.
다른 배포본들도 마찬가지라면, uuencode/decode 가 있을지 없을지 장담 못합니다.

누군가 보지 못하게 바꿔놓기 위해서라면,
shar 는 비추천입니다. 자동풀림 스크립트로 결과물이 나옵니다.
gpg 를 추천합니다만, 키를 들고다녀야만 하니 좀 불편하겠군요.

OTL

aero의 이미지

기본설치 리눅스에서 Perl은 다 깔려있을 것이니
Perl의 배포시 기본으로 포함되는 MIME::Base64 모듈을 사용하는 방법입니다.

test.txt

Hello, World!
Hello, KLDP!

인코딩

cat test.txt | perl -MMIME::Base64 -e 'local $/;print MIME::Base64::encode_base64(<STDIN>)' > encrypt.txt

encrypt.txt

SGVsbG8sIFdvcmxkIQpIZWxsbywgS0xEUCEK

디코딩

cat encrypt.txt | perl -MMIME::Base64 -e 'local $/;print MIME::Base64::decode_base64(<STDIN>)' > decrypt.txt

decrypt.txt

Hello, World!
Hello, KLDP!

이건 base64인코딩이란걸 알면 금방 풀 수 있겠지만~
본격적인 암호화 복호화를 하려면 암호화 관련 모듈을 설치하든지 특정 프로그램을 설치하든지 추가 작업이 들어가야 하겠죠.

nonots의 이미지

답변 감사합니다...
좋은 방법이네요..
그런데 여기에서
local $/; 이부분은 어떤 역할을 하나요?
없어도 결과가 똑같군요..

=== 건달의 경지를 꿈꾸며 ===


=== 건달의 경지를 꿈꾸며 ===

monovision의 이미지

타 배포판은 모르겠지만...... 레뎃 계열에서는 base64 프로그램이 기본적으로 설치가 되어 있습니다.

[root@localhost ~]# cat > test.txt
hello.
kldp.org
^C
[root@localhost ~]# base64 test.txt > crypt
[root@localhost ~]# cat crypt
aGVsbG8uCmtsZHAub3JnCg==
[root@localhost ~]# base64 -di < crypt > decrypt
[root@localhost ~]# cat decrypt
hello.
kldp.org
[root@localhost ~]#

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.