当前位置: 首页 > news >正文

如何建设一个收费的影视图文网站编程教程免费视频

如何建设一个收费的影视图文网站,编程教程免费视频,免费搭建贴吧系统网站,什么网站可以做项目要完成properties属性文件某些属性值的加密#xff0c;和读取属性文件时进行解密#xff0c;需要4个步骤 编写加密解密工具类手动通过加密解密工具类获得加密后的属性值密文#xff0c;并把密文填写在properties文件中编写PropertyPlaceholderConfigurer的子类#xff0c;…要完成properties属性文件某些属性值的加密和读取属性文件时进行解密需要4个步骤 编写加密解密工具类手动通过加密解密工具类获得加密后的属性值密文并把密文填写在properties文件中编写PropertyPlaceholderConfigurer的子类重写convertProperty()方法在spring-dao.xml配置文件中配置PropertyPlaceholderConfigurer类 接下来我们将拿配置数据库的properties文件进行举例一般我们需要对用户名和密码进行加密 编写加密解密工具类 在编写工具类前我们需要导入包含Base64这个类的依赖 dependencygroupIdcommons-codec/groupIdartifactIdcommons-codec/artifactIdversion1.14/version /dependency之所以要使用Base64对加密后的byte数组进行编码可以参考Base64编码及其作用 编写使用DES加密算法的加密解密工具类 package com.lxc.o2o.util; import java.io.UnsupportedEncodingException; import java.security.Key; import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import org.apache.commons.codec.binary.Base64;/*** DES是一种对称加密算法所谓对称加密算法即加密和解密使用相同密钥的算法。* */ public class DESUtil {// 秘钥对象private static Key key;// 设置密钥keyprivate static String KEY_STR myKey;// 使用的编码private static String CHARSETNAME UTF-8;// 设置使用DES算法我们这里主要使用java的DES算法private static String ALGORITHM DES;// 初始化秘钥对象keystatic {try {// 生成DES算法对象KeyGenerator generator KeyGenerator.getInstance(ALGORITHM);// 运用SHA1安全策略SecureRandom secureRandom SecureRandom.getInstance(SHA1PRNG);// 设置上密钥种子secureRandom.setSeed(KEY_STR.getBytes());// 初始化基于SHA1的算法对象generator.init(secureRandom);// 生成密钥对象key generator.generateKey();generator null;} catch (Exception e) {throw new RuntimeException(e);}}/*** 获取加密后的信息* * param str* return*/public static String getEncryptString(String str) {try {// 按UTF8编码byte[] bytes str.getBytes(CHARSETNAME);// 获取加密对象Cipher cipher Cipher.getInstance(ALGORITHM);// 初始化密码信息Cipher.ENCRYPT_MODE为加密类型cipher.init(Cipher.ENCRYPT_MODE, key);// 加密byte[] doFinal cipher.doFinal(bytes);// 基于BASE64编码接收byte[]并转换成String// byte[]to encode好的String并返回编码成字符串返回return Base64.encodeBase64String(doFinal);} catch (Exception e) {// TODO: handle exceptionthrow new RuntimeException(e);}}/*** 获取解密之后的信息* * param str* return*/public static String getDecryptString(String str) {try {// 基于BASE64编码接收byte[]并转换成String// 将字符串decode成byte[]解码操作byte[] bytes Base64.decodeBase64(str);// 获取解密对象Cipher cipher Cipher.getInstance(ALGORITHM);// 初始化解密信息cipher.init(Cipher.DECRYPT_MODE, key);// 解密byte[] doFinal cipher.doFinal(bytes);// 返回解密之后的信息return new String(doFinal, CHARSETNAME);} catch (Exception e) {// TODO: handle exceptionthrow new RuntimeException(e);}}public static void main(String[] args) throws UnsupportedEncodingException {System.out.println(getEncryptString(root));System.out.println(getEncryptString(123456));}}获取用户名和密码的秘文 通过上面编写的DESUtil获取用户名和密码的密文再把密文填写进jdbc.properties文件 jdbc.drivercom.mysql.cj.jdbc.Driver jdbc.urljdbc:mysql://localhost:3306/myo2o?useSSLfalseserverTimezoneAsia/ShanghaiuseUnicodetruecharacterEncodingutf8 jdbc.usernameWnplV/ietfQ jdbc.passwordQAHlVoUc49w编写PropertyPlaceholderConfigurer的子类 package com.lxc.o2o.util; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; /*** 获取解密后的属性值*/ public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {// 需要加密的字段数组这里整个jdbc属性文件我们只对username和password加密了private String[] encryptPropNames { jdbc.username, jdbc.password };/*** 对关键的属性进行转换重写PropertyPlaceholderConfigurer中的convertProperty方法* 这个函数会对属性文件中所有的属性键值对进行读取*/Overrideprotected String convertProperty(String propertyName, String propertyValue) {// 判断属性值是否被加密了if (isEncryptProp(propertyName)) {// 对已加密的字段进行解密工作String decryptValue DESUtil.getDecryptString(propertyValue);return decryptValue;} else {// 如果没被加密直接返回return propertyValue;}}/*** 判断该属性是否已加密主要拿传进来的属性名和上面我们定义的需要加密的字段数组进行比对* * param propertyName* return*/private boolean isEncryptProp(String propertyName) {// 若等于需要加密的field则进行加密for (String encryptpropertyName : encryptPropNames) {if (encryptpropertyName.equals(propertyName))return true;}return false;} }配置Bean 在spring-dao.xml配置文件中配置我们自己实现的EncryptPropertyPlaceholderConfigurer类 !--连接数据库时会自动读取对应的配置文件并进行解密操作-- bean classcom.lxc.o2o.util.EncryptPropertyPlaceholderConfigurerproperty namelocationslistvalueclasspath:jdbc.properties/value!-- 如果要读取其他加密的配置文件继续配置在这个list中 --/list/propertyproperty namefileEncoding valueUTF-8/property /bean运行时创建了上面的bean后可以直接通过${属性名}获取解密后的属性值 !-- 2.数据库连接池 -- bean iddataSource classcom.mchange.v2.c3p0.ComboPooledDataSource!--配置连接池属性 --property namedriverClass value${jdbc.driver}/propertyproperty namejdbcUrl value${jdbc.url}/propertyproperty nameuser value${jdbc.username}/propertyproperty namepassword value${jdbc.password}/property /bean 12345678到这里我们就完成了加密和解密properties文件的所有操作
http://www.pierceye.com/news/355349/

相关文章:

  • 软件制作网站网站维护合同模板
  • 那家财经网站做的好陕西网站建设公司哪有
  • 淄川网站建设中小型企业网站建设
  • phpcms 投资 网站源码wordpress主题网站
  • 聊城网站托管义乌外贸公司联系方式
  • 开发一个小程序对网站做综合搜索引擎优化分析
  • 网站开发自学网有哪些企业可以做招聘的网站有哪些
  • 网站怎么做百度推广网站开发者模式
  • 学校网站设计制作目的做网站推广方法
  • wordpress建站云平台小程序商城开发平台
  • pc网站转换成微网站网站建设开发哪家质量好
  • wordpress网站使用教程aspnet东莞网站建设多少钱
  • 网站地图提交给百度证券公司如何拉客户
  • 做外贸有哪些免费的网站win7优化大师好不好
  • 网站功能怎么写上海网站制作建设怎么样
  • 网站域名是网站架构吗成都网站搭建优化推广
  • 自己做的网站添加交费功能合肥有什么好的网站建设公司好
  • 做网站品牌龙岩新增病例行动轨迹
  • 任家房网站建设郑州百度网站推广
  • 深圳建设网站的公司简介WordPress多功能投稿
  • 简述织梦网站上传及安怎样在网站上做免费的推广
  • 关于信用体系建设的网站wordpress新闻类模板下载
  • 免费行情软件网站下载大全爱学校vi设计案例
  • 网站外包优化怎样做免费抽皮肤的网站
  • 东八区网站建设网站源码在哪里
  • 重点建设专业 专题网站搜狗官方网站
  • 微信营销工具有哪些使用最佳搜索引擎优化工具
  • 网站推广意识薄弱wordpress授权协议
  • 用php做高中数学题库网站阿里网站建设教程
  • 大兴网站建设公司电话东莞企业网站制作怎么做