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.util.StringUtil;
019import org.opengion.fukurou.security.HybsCryptography ;
020import org.opengion.hayabusa.db.AbstractDBType;
021
022/**
023 * 半角/全角混在の一般的な制限のない暗号化された文字列を扱う為の、カラム属性を定義します。
024 *
025 * ログイン認証のパスワードなどは、MD5などのハッシュコードに変換する方式が使えます。
026 * これは、非可逆変換なので、変換後の文字列は、元に戻すことは出来ません。
027 * 一般には、この非可逆変換が使用できるのであれば、漏洩に対しては安全です。
028 * このクラスの暗号化は秘密キーによる可逆変換なので、変換方式と秘密キーが判ると
029 * 元に戻すことが可能です。それでも、何もしないよりははるかにましです。
030 * データベース等へ登録したデータを戻して利用したいが、そのまま抜き出されるのは
031 * 困る場合に、使用できます。
032 * なお、暗号化するため、元データの整合性ではなく暗号化された後のデータでの整合性が
033 * チェックされます。
034 *
035 * @og.rev 4.0.0.0 (2005/08/31) 新規作成
036 * @og.group データ属性
037 *
038 * @version  4.0
039 * @author   Kazuhiko Hasegawa
040 * @since    JDK5.0,
041 */
042public class DBType_CRYPT extends AbstractDBType {
043        /** このプログラムのVERSION文字列を設定します。   {@value} */
044        private static final String VERSION = "6.4.2.0 (2016/01/29)" ;
045
046        private final HybsCryptography licence = new HybsCryptography() ;
047
048        /**
049         * デフォルトコンストラクター
050         *
051         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
052         */
053        public DBType_CRYPT() { super(); }              // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
054
055        /**
056         * String引数の文字列を+1した文字列を返します。
057         * ※ このクラスでは実装されていません。
058         *
059         * @og.rev 5.6.0.3 (2012/01/24) ADD に、引数の値を加算する機能を追加します。
060         *
061         * @param   value  String引数
062         * @param   add    加算する文字列(null の場合は、従来と同じ、+1 します。)
063         *
064         * @return  引数の文字列を+1した文字列。または、任意の値を加算した文字列。
065         * @throws UnsupportedOperationException このクラスを実行すると、必ず発生します。
066         */
067        @Override
068        public String valueAdd( final String value,final String add ) {
069                final String errMsg = "このメソッドは、このクラスからは使用できません。";
070                throw new UnsupportedOperationException( errMsg );
071        }
072
073        /**
074         * HybsCryptographyにより、暗号化された文字を返します。
075         *
076         * HybsCryptography クラスを使用した、秘密キー暗号化方式により、登録データを暗号化します。
077         * 暗号化されたバイト文字は、16進数で文字列に変換しています。
078         *
079         * @param   value 一般に編集データとして登録されたデータ
080         *
081         * @return  修正後の文字列(一般にデータベースに登録するデータ)
082         */
083        @Override
084        public String valueSet( final String value ) {
085                return licence.encrypt( StringUtil.rTrim( value ) );
086        }
087}