1.依存紹介
< 依存性> < のgroupId > com.github.ulisesbocchio </ のgroupId > < たartifactId > jasyptスプリングブートスタータ</ たartifactId > < バージョン> 2.0.0 </ バージョン> </ 依存>
設定ファイル
db.password = ENC(XvP2P4H3cLzf8r / ak91xLg ==)
で2.controller
パッケージcom.example.configcenter。 輸入org.jasypt.intf.service.JasyptStatelessService。 輸入org.springframework.beans.factory.annotation.Value。 輸入org.springframework.web.bind.annotation.PostMapping。 輸入org.springframework.web.bind.annotation.RequestMapping。 輸入org.springframework.web.bind.annotation.RestController。 輸入javax.annotation.Resource。 @RequestMapping( "/ ConfigClientDemo" ) @RestController パブリック クラスConfigClientDemoController { @value( "$ {db.password}" ) プライベート文字列のテスト名。
@PostMapping(「/ getServiceMethod」) パブリック文字列エコー(文字列名){ リターン「ワッハッハー」+名。 } @PostMapping( "/暗号化" ) パブリック文字列暗号化(文字列入力文字列encodeKey){ JasyptStatelessServiceサービス = 新しいJasyptStatelessService()。 文字列結果 = service.encrypt(入力、encodeKey、(文字列)ヌル(文字列)ヌル、 "PBEWithMD5AndDESは"、(文字列)ヌル(文字列)ヌル(文字列)ヌル(文字列)ヌル(文字列)はnull、(文字列)ヌル(文字列)ヌル(文字列)ヌル(文字列)ヌル(文字列)ヌル(文字列)ヌル(文字列)ヌル(文字列)ヌル(文字列)ヌル(文字列)はnull、(文字列)ヌル、(文字列)NULL ); 戻り値の結果; } }
3. [スタート]キーパラメータが追加します
-Djasypt.encryptor.password = PWD
4.コール
http:// localhostを:?8705 / ConfigClientDemo /暗号入力= 123456&encodeKey = PWD
戻り値:XvP2P4H3cLzf8r / ak91xLg ==
この設定ファイルを配置
再起動プロジェクト
アクセス方法
"ワッハッハー" + STR