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 = "5.6.0.3 (2012/01/24)" ; 045 046 private final HybsCryptography licence = new HybsCryptography() ; 047 048 /** 049 * String引数の文字列を+1した文字列を返します。 050 * ※ このクラスでは実装されていません。 051 * 052 * @og.rev 5.6.0.3 (2012/01/24) ADD に、引数の値を加算する機能を追加します。 053 * 054 * @param value String引数 055 * @param add 加算する文字列(null の場合は、従来と同じ、+1 します。) 056 * 057 * @return 引数の文字列を+1した文字列。または、任意の値を加算した文字列。 058 * @throws UnsupportedOperationException このクラスを実行すると、必ず発生します。 059 */ 060 @Override 061 public String valueAdd( final String value,final String add ) { 062 String errMsg = "このメソッドは、このクラスからは使用できません。"; 063 throw new UnsupportedOperationException( errMsg ); 064 } 065 066 /** 067 * HybsCryptographyにより、暗号化された文字を返します。 068 * 069 * HybsCryptography クラスを使用した、秘密キー暗号化方式により、登録データを暗号化します。 070 * 暗号化されたバイト文字は、16進数で文字列に変換しています。 071 * 072 * @param value 一般に編集データとして登録されたデータ 073 * 074 * @return 修正後の文字列(一般にデータベースに登録するデータ) 075 */ 076 @Override 077 public String valueSet( final String value ) { 078 return licence.encrypt( StringUtil.rTrim( value ) ); 079 } 080}