・正規表現による抽出
REGEXP_SUBSTR(string,pattern
[,position[,occurrence[,match_param[,sub_pattern_pos]]]])
引数
string 対象の文字列式
pattern 正規表現パターン
position 取り出したい文字列の開始位置(1~) default 1
occurence 取り出すまでの検知回数 default 1
match_param 検索パラメータ
sub_pat_pos 取り出すサブパターン位置(\0,\1などに相当)
検索パラメータ
c 大文字小文字を区別する(Case sensitive)
i 大文字小文字を区別しない(case Insensitive / Ignore)
m ^$メタ記号を各行の先頭と末尾に一致させる(Multiple lines)
n メタ記号のドット(.)を改行にも一致させる(Newline)
x 空白を取り除いて評価する(eXcluding white-space)
REGEXP_SUBSTR(COL,'^FILE:(.*)$',1,1,m,1)
FILE:/usr/local/test.log
SETTING:a=123
ERRID:M99999-E
NORMID:M00001-I
↓
/usr/local/test.log
2015年2月3日火曜日
簡易暗号化テキスト
ファイル添付を避けたい場合など
ZIP圧縮で暗号化、BASE64で可読テキスト化
ファイル名も隠す場合は2回ZIPに包む
ZIPでBASE64の冗長化をある程度相殺できる
・ファイルをPWつきZIP
※PWないとbase64-decodeすると内容がわかってしまう
※ファイル名を見られたくない場合、も一度PWつきZIPにする
・base64-encode
***テキストとして送受信
・base64-decode、ファイルに書込み
・ファイルをZIPとして解凍(PWを入力)
※2回zipしている場合は2回解凍
<例>
TEXT 4.5KB
ZIP 3.4KB
BASE64 4.7KB
ZIP圧縮で暗号化、BASE64で可読テキスト化
ファイル名も隠す場合は2回ZIPに包む
ZIPでBASE64の冗長化をある程度相殺できる
・ファイルをPWつきZIP
※PWないとbase64-decodeすると内容がわかってしまう
※ファイル名を見られたくない場合、も一度PWつきZIPにする
・base64-encode
***テキストとして送受信
・base64-decode、ファイルに書込み
・ファイルをZIPとして解凍(PWを入力)
※2回zipしている場合は2回解凍
<例>
TEXT 4.5KB
ZIP 3.4KB
BASE64 4.7KB
LinuxでBASE64
・素直にbase64
echo "test" | base64
dGVzdA==
echo "dGVzdA==" | base64 -b
test
cat test.txt | base64 > test_b64.txt
cat test_b64.txt | base64 -d > test_b64_dec.txt
・またはnkf
echo "test" | nkf -MB
dGVzdA==
echo "dGVzdA==" | nkf -mB
test
cat test.txt | nkf -MB > test_b64.txt
cat test_b64.txt | nkf -mB -d > test_b64_dec.txt
echo "test" | base64
dGVzdA==
echo "dGVzdA==" | base64 -b
test
cat test.txt | base64 > test_b64.txt
cat test_b64.txt | base64 -d > test_b64_dec.txt
・またはnkf
echo "test" | nkf -MB
dGVzdA==
echo "dGVzdA==" | nkf -mB
test
cat test.txt | nkf -MB > test_b64.txt
cat test_b64.txt | nkf -mB -d > test_b64_dec.txt
WindowsでBASE64
・Windowsではcertutilコマンドで
certutil -encode aaa.txt aaa_base64.txt
certutil -decode aaa_base64.txt aaa.txt
type test.txt
テスト
certutil -encode test.txt test_base64.txt
type test_base64.txt
-----BEGIN CERTIFICATE-----
g2WDWINnIA0K
-----END CERTIFICATE-----
certutil -decode test_base64.txt test_base64_de.txt
type test_base64_de.txt
テスト
certutil -encode aaa.txt aaa_base64.txt
certutil -decode aaa_base64.txt aaa.txt
type test.txt
テスト
certutil -encode test.txt test_base64.txt
type test_base64.txt
-----BEGIN CERTIFICATE-----
g2WDWINnIA0K
-----END CERTIFICATE-----
certutil -decode test_base64.txt test_base64_de.txt
type test_base64_de.txt
テスト
2015年2月2日月曜日
OracleでBASE64
・utl_encodeのbase64_encodeを使用
・raw形式にキャストして入力
SELECT utl_encode.base64_encode( utl_raw.cast_to_raw( TARGET_COLUMN)) FROM TABLE;
・raw形式にキャストして入力
SELECT utl_encode.base64_encode( utl_raw.cast_to_raw( TARGET_COLUMN)) FROM TABLE;
----------------
Hello01!
↓
SGVsbG8wMSE=
----------------
Hello01!
↓
SGVsbG8wMSE=
----------------
登録:
投稿 (Atom)