序文
この記事では、主にJASYPTに関連する方法を紹介して、Spring Boot Configurationファイルを暗号化します。以下ではあまり言いません。詳細な紹介を一緒に見てみましょう。
この方法は次のとおりです。
Jasyptの紹介
<Dependency> groupId> com.github.ulisesbocchio </groupid> <artifactid> jasypt-spring-boot-starter </artifactid> <バージョン> 2.0.0 </version> </dependency>
暗号化される文字列を生成します
データベースのユーザー名とパスワードを暗号化します
public static void main(string [] args){basictextencryptor textencryptor = new basictextencryptor(); //暗号化に必要な塩(塩)TextEncryptor.setPassWord( "g0cvdz7ojn6"); //暗号化されるデータ(データベースのユーザー名またはパスワード)文字列username = textencryptor.encrypt( "root");文字列パスワード= TextEncryptor.Encrypt( "root123"); system.out.println( "username:"+username); System.out.println( "password:"+password); }出力情報は次のとおりです。
ユーザー名:i8qgen4uoy2e1rhzrpstya ==
パスワード:6eamh/rx5oxuvca9ignvtg ==
または、Mavenを使用してJarパッケージをダウンロードして/maven/org/jasypt/jasypt/1.9.2/jasypt-1.9.2.jarを暗号化します
Java -cp Jasypt -1.9.2.jar org.jasypt.intf.cli.jasyptpbestringencryptioncli password = g0cvdz7ojn6 algorithm = pbewithmd5anddes input = root
出力情報は次のとおりです。
- -環境 - - - - - - - - - - -
ランタイム:Oracle Corporation Java Hotspot(TM)64ビットサーバーVM 25.171-B11---ARGUMENTS-----------------------------------------------------------------------------------------------------------------------
入力:ルート
アルゴリズム:pbewithmd5anddes
パスワード:G0CVDZ7OJN6- -出力 - - - - - - - - - - - - - -
gvkoz+sbfwire3ectizv1a ==
出力の下で結果をコピーするだけです -
プロパティファイルを構成します
生成された暗号化文字列enc(暗号化文字列)をApplication.Propertiesに構成する
#暗号化に必要な塩(塩)jasypt.encryptor.password = g0cvdz7ojn6#デフォルトの暗号化方法pbewithmd5anddesは、pbewithmd5andtripledes#に変更できますjasypt.encryptor.algorithm = pbewithmd5anddesspring.datasource.username = enc(6eamh/rx5oxuvca9ignvtg ==)spring .datasource.password = enc(6eamh/rx5oxuvca9ignvtg ==)spring.datasource.password = enc(6eamh/rx5oxuvca9ignvtg ==)
暗号化の対応するクラスは、BasictextEncryptorとStrongTextEncryptorです
public basictextencryptor(){super(); this.encryptor = new StandardPbestringEncryptor(); this.encryptor.setalgorithm( "pbewithmd5anddes");} public strongTextEncryptor(){super(); this.encryptor = new StandardPbestringEncryptor(); this.encryptor.setalgorithm( "pbewithmd5andtripledes");}クラス図
展開中に塩値を構成します
塩(塩)が漏れないようにするために、パスワードを解き放ちます。コマンドを使用して、プロジェクトを展開するときに塩(塩)値を渡すことができます。
Java -jar -djasypt.encryptor.password = g0cvdz7ojn6 xxx.jar
または、セキュリティをさらに改善するためにサーバー環境変数でそれを構成する
/etc /プロフィールファイルを開きます
Vim /etc /プロファイルファイルの最後に挿入します
export jasypt_password = g0cvdz7ojn6編集
ソース /など /プロファイル走る
java -jar -djasypt.encryptor.password = $ {jasypt_password} xxx.jar
公式住所:https://github.com/ulisesbocchio/jasypt-spring-boot(ローカルダウンロード)
要約します
上記は、この記事のコンテンツ全体です。この記事の内容には、すべての人の研究や仕事に特定の参照値があることを願っています。ご質問がある場合は、メッセージを残してコミュニケーションをとることができます。 wulin.comへのご支援ありがとうございます。