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 * パスワード情報など、重要な情報のハッシュコード(SHA-1)を扱う為の、カラム属性を定義します。 024 * 025 * パスワード情報など、重要な情報のハッシュコードに、SHA-1 があります。このクラスは、 026 * MessageDigestにより、SHA-1 でハッシュした文字を作成します。 027 * 028 * 値としては、標準の X と同じ半角文字列「 c < 0x20 || c > 0x7e 以外」でのみ 029 * 処理することが出来ます。 030 * 031 * タイプチェックとして、以下の条件を判定します。 032 * ・文字列長は、Byte換算での文字数との比較 033 * ・半角文字列チェック「 c < 0x20 || c > 0x7e 以外」エラー 034 * ・文字パラメータの 正規表現チェック 035 * ・クロスサイトスクリプティングチェック 036 * 037 * @og.group データ属性 038 * 039 * @version 4.0 040 * @author Takahashi Masakazu 041 * @since JDK5.0, 042 */ 043public class DBType_SHA1 extends AbstractDBType { 044 //* このプログラムのVERSION文字列を設定します。 {@value} */ 045 private static final String VERSION = "5.9.27.1 (2017/12/08)" ; 046 047 /** 048 * String引数の文字列を+1した文字列を返します。 049 * ※ このクラスでは実装されていません。 050 * 051 * @param value String引数の文字列 052 * @throws UnsupportedOperationException このクラスを実行すると、必ず発生します。 053 * 054 * @return String引数の文字列を+1した文字列 055 */ 056 @Override 057 public String valueAdd( final String value ) { 058 String errMsg = "このメソッドは、このクラスからは使用できません。"; 059 throw new UnsupportedOperationException( errMsg ); 060 } 061 062 /** 063 * MessageDigestにより、SHA-1 でハッシュした文字を返します。 064 * 065 * マイナス時には符号を反転させて、16進数で文字列に変換しています。 066 * よって、このメソッドで変換した文字でのみ突き合わせて正しいかどうかを 067 * 判断してください。 068 * 069 * 070 * @param value (一般に編集データとして登録されたデータ) 071 * 072 * @return 修正後の文字列(一般にデータベースに登録するデータ) 073 */ 074 @Override 075 public String valueSet( final String value ) { 076 return HybsCryptography.getSHA1( StringUtil.rTrim( value ) ); 077 } 078}