001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.plugin.column; 017 018import org.opengion.fukurou.security.HybsCryptography; 019import org.opengion.fukurou.util.StringUtil; 020import org.opengion.hayabusa.db.AbstractDBType; 021 022/** 023 * パスワード情報など、重要な情報のハッシュコード(MD5)を扱う為の、カラム属性を定義します。 024 * 025 * パスワード情報など、重要な情報のハッシュコードに、MD5 があります。このクラスは、 026 * MessageDigestにより、MD5 でハッシュした文字を作成します。 027 * 値としては、標準の X と同じ半角文字列「 c < 0x20 || c > 0x7e 以外」でのみ 028 * 処理することが出来ます。 029 * 030 * タイプチェックとして、以下の条件を判定します。 031 * ・文字列長は、Byte換算での文字数との比較 032 * ・半角文字列チェック「 c < 0x20 || c > 0x7e 以外」エラー 033 * ・文字パラメータの 正規表現チェック 034 * ・クロスサイトスクリプティングチェック 035 * 036 * @og.group データ属性 037 * 038 * @version 4.0 039 * @author Kazuhiko Hasegawa 040 * @since JDK5.0, 041 */ 042public class DBType_MD5 extends AbstractDBType { 043 //* このプログラムのVERSION文字列を設定します。 {@value} */ 044 private static final String VERSION = "5.2.2.0 (2010/11/01)" ; 045 046 /** 047 * String引数の文字列を+1した文字列を返します。 048 * ※ このクラスでは実装されていません。 049 * 050 * @param value String引数の文字列 051 * @throws UnsupportedOperationException このクラスを実行すると、必ず発生します。 052 * 053 * @return String引数の文字列を+1した文字列 054 */ 055 @Override 056 public String valueAdd( final String value ) { 057 String errMsg = "このメソッドは、このクラスからは使用できません。"; 058 throw new UnsupportedOperationException( errMsg ); 059 } 060 061 /** 062 * MessageDigestにより、MD5 でハッシュした文字を返します。 063 * 064 * MD5で、15Byteのバイトに変換されますが、ここでは、マイナス時には, 065 * 符号を反転させて、16進数で文字列に変換しています。 066 * よって、このメソッドで変換した文字でのみ突き合わせて正しいかどうかを 067 * 判断してください。 068 * 069 * @og.rev 3.3.3.0 (2003/07/09) 前後のスペースを取り除いておく。 070 * @og.rev 3.3.3.1 (2003/07/18) 後ろスペースを取り除く。(StringUtil#rTrim) 071 * @og.rev 5.2.2.0 (2010/11/01) util.StringUtil から security.HybsCryptography へ移動 072 * 073 * @param value (一般に編集データとして登録されたデータ) 074 * 075 * @return 修正後の文字列(一般にデータベースに登録するデータ) 076 */ 077 @Override 078 public String valueSet( final String value ) { 079// return StringUtil.getMD5( StringUtil.rTrim( value ) ); 080 return HybsCryptography.getMD5( StringUtil.rTrim( value ) ); // 5.2.2.0 (2010/11/01) クラス変更 081 } 082}