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