数据加密技术篇

前端常见的数据加密 你是否有过这样的经历?在注册一个新网站时,需要填写个人信息,例如姓名、邮箱、手机号码,甚至身份证号码。你可能会担心,这些信息会被泄露,被不法分子利用。前端数据加密,就是解决这个问题的关键技术之一。它可以在数据传输到服务器之前,对其进行加密处理,即使数据被窃取,也无法被轻易破解。提示:以下是本篇文章正文内容,下面案例可供参考前端数据加密是指在数据从用户浏览器传输到服务器之前,对其进行加密处理的技术。它将明文数据转换为密文,即使数据在传输过程中被截获,也无法被轻易读取或篡改。前端数据加密 vs 后端数据加密。 阅读详情
	 这几年接触了一些加密技术,在这里做个总结,主要是加密算法(对称加密和非对称加密)和摘要算法。这里主要是结合Java代码讲解常见的 对称加密(DES)、非对称加密(RSA)、摘要算法(MD5)

对称加密:DES,3DES,TDEA,Blowfish,RC5,IDEA等。
非对称加密:RSA、Elgamal、背包算法、Rabin、D-H、ECC等
摘要算法:MD5算法和SHA-1算法等

对称加密(DES):对称加密算法是应用较早的加密算法,技术成熟。在对称加密算法中,使用的密钥只有一个,发收信双方都使用这个密钥对数据进行加密和解密,这就要求解密方事先必须知道加密密钥。

import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;

	public class DesUtils {    
		private static final String DES = "DES";
		private static final String ***KEY*** = "3YxxxxxxxxxZF"; //自定义
		
		private DesUtils() {}
		
		private static byte[] encrypt(byte[] src, byte[] key) throws Exception {
		    SecureRandom sr = new SecureRandom();
		    DESKeySpec dks = new DESKeySpec(key);
		    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
		    SecretKey secretKey = keyFactory.generateSecret(dks);
		    Cipher cipher = Cipher.getInstance(DES);
		    cipher.init(Cipher.ENCRYPT_MODE, secretKey, sr);
		    return cipher.doFinal(src);
		}
		
		private static byte[] decrypt(byte[] src, byte[] key) throws Exception {
		    SecureRandom sr = new SecureRandom();
		    DESKeySpec dks = new DESKeySpec(key);
		    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
		    SecretKey secretKey = keyFactory.generateSecret(dks);
		    Cipher cipher = Cipher.getInstance(DES);
		    cipher.init(Cipher.DECRYPT_MODE, secretKey, sr);
		    return cipher.doFinal(src);
		}
		
		private static String byte2hex(byte[] b) {
		    String hs = "";
		String temp = "";
		for (int n = 0; n < b.length; n++) {
		    temp = (java.lang.Integer.toHexString(b[n] & 0XFF));
		    if (temp.length() == 1)
		        hs = hs + "0" + temp;
		        else
		            hs = hs + temp;
		    }
		    return hs.toUpperCase();
		
		}
		
		private static byte[] hex2byte(byte[] b) {
		    if ((b.length % 2) != 0)
		        throw new IllegalArgumentException("length not even");
		    byte[] b2 = new byte[b.length / 2];
		    for (int n = 0; n < b.length; n += 2) {
		        String item = new String(b, n, 2);
		        b2[n / 2] = (byte) Integer.parseInt(item, 16);
		    }
		    return b2;
		}
		
		private static String decode(String src, String key) {
		    String decryptStr = "";
		    try {
		        byte[] decrypt = decrypt(hex2byte(src.getBytes()), key.getBytes());
		        decryptStr = new String(decrypt);
		    } catch (Exception e) {
		        e.printStackTrace();
		    }
		    return decryptStr;
		}
		
		private static String encode(String src, String key){
		    byte[] bytes = null;
		    String encryptStr = "";
		    try {
		        bytes = encrypt(src.getBytes(), key.getBytes());
		    } catch (Exception ex) {
		        ex.printStackTrace();
		    }
		    if (bytes != null)
		        encryptStr = byte2hex(bytes);
		    return encryptStr;
		}
		
		/**
		 * 解密
		 */
		public static String decode(String src) {
		    return decode(src, KEY);
		}
		
		/**
		 * 加密
		 */
		public static String encode(String src) {
		    return encode(src, KEY);
		}
		
		//测试方法main
		public static void main(String[] args) {
		    String ss = "dawng";
		    String encodeSS = encode(ss);
		    System.out.println(encodeSS);
		    String decodeSS = decode(encodeSS);
		    System.out.println(decodeSS);
		}
}

非对称加密(RSA):非对称加密算法需要两个密钥:公开密钥(publickey:简称公钥)和私有密钥(privatekey:简称私钥)。公钥与私钥是一对,如果用公钥对数据进行加密,只有用对应的私钥才能解密。
注:RSA加密除了公钥私钥,还有秘钥的长度有关。
(如果不想用签名可以注释掉签名部分即可)

import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import javax.crypto.Cipher;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
 
public class RSAUtils{
    public static final String KEY_ALGORITHM="RSA";
    public static final String SIGNATURE_ALGORITHM="MD5withRSA";
    private static final int KEY_SIZE=1024;	//长度和加密时一致
    private static final String PUBLIC_KEY="RSAPublicKey";
    private static final String PRIVATE_KEY="RSAPrivateKey";
    public static String str_pubK = "MIGxxxxxxxxxxxxx8=";	//和前端加密的私钥对应起来
    
      
      /**
       * 使用getPublicKey得到公钥,返回类型为PublicKey
       * @param base64 String to PublicKey
       * @throws Exception
       */
      public static PublicKey getPublicKey(String key) throws Exception {
            byte[] keyBytes;
            keyBytes = (new BASE64Decoder()).decodeBuffer(key);
            X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            PublicKey publicKey = keyFactory.generatePublic(keySpec);
            return publicKey;
      }
      /**
       * 转换私钥
       * @param base64 String to PrivateKey
       * @throws Exception
       */
      public static PrivateKey getPrivateKey(String key) throws Exception {
            byte[] keyBytes;
            keyBytes = (new BASE64Decoder()).decodeBuffer(key);
            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
            return privateKey;
      }

      //***************************签名和验证*******************************
      public static byte[] sign(byte[] data) throws Exception{
        PrivateKey priK = getPrivateKey(str_priK);
          Signature sig = Signature.getInstance(SIGNATURE_ALGORITHM);        
          sig.initSign(priK);
          sig.update(data);
          return sig.sign();
      }
      
      public static boolean verify(byte[] data,byte[] sign) throws Exception{
          PublicKey pubK = getPublicKey(str_pubK);
          Signature sig = Signature.getInstance(SIGNATURE_ALGORITHM);
          sig.initVerify(pubK);
          sig.update(data);
          return sig.verify(sign);
      }
      
      //************************加密解密**************************
      public static byte[] encrypt(byte[] bt_plaintext)throws Exception{
          PublicKey publicKey = getPublicKey(str_pubK);
          Cipher cipher = Cipher.getInstance("RSA");
          cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        byte[] bt_encrypted = cipher.doFinal(bt_plaintext);
        return bt_encrypted;
      }
      
      public static byte[] decrypt(byte[] bt_encrypted)throws Exception{
        PrivateKey privateKey = getPrivateKey(str_priK);
        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.DECRYPT_MODE, privateKey);
        byte[] bt_original = cipher.doFinal(bt_encrypted);
        return bt_original;
      }
      
      //********************main函数:加密解密和签名验证*********************
      public static void main(String[] args) throws Exception {
            String str_plaintext = "这是一段用来测试密钥转换的明文";
            System.err.println("明文结果:"+str_plaintext);
            byte[] bt_cipher = encrypt(str_plaintext.getBytes());
            System.out.println("加密后结果:"+Base64.encodeBase64String(bt_cipher));
    	  
            byte[] bt_original = decrypt(bt_cipher);
            String str_original = new String(bt_original);
            System.out.println("解密结果:"+str_original);
            
            String str="被签名的内容";
            System.err.println("\n原文:"+str);
            byte[] signature=sign(str.getBytes());
            System.out.println("产生签名值:"+Base64.encodeBase64String(signature));
            boolean status=verify(str.getBytes(), signature);
            System.out.println("验证结果:"+status);
      }
 
}

摘要加密(MD5):消息摘要算法的主要特征是加密过程不需要密钥,并且经过加密的数据无法被解密,目前可以被解密逆向的只有CRC32算法,只有输入相同的明文数据经过相同的消息摘要算法才能得到相同的密文。
注:项目配置一个shiro的jar即可

导入 import org.apache.shiro.crypto.hash.Md5Hash;

注册时对用户输入的密码继续MD5加密,将加密的密码存入数据库
    //  密码            				盐值 搅拌次数
Md5Hash mh = new Md5Hash(Password,"yanzhi",3);
Password = mh.toString(); 

登录时对用户登录的密码进行相同加密,用加密后的值与数据库中加密的密码继续匹配
Md5Hash mh = new Md5Hash(Password,"yanzhi",3);
Password = mh.toString(); 
用CryptoAPI进行数据加密 http://expert.youkuaiyun.com/Expert/topic/1034/1034228.xml?temp=.8807794 用CryptoAPI进行数据加密 南京理工大学计算机系 胡静 李蔚清   由于过于复杂的加密算法实现起来非常困难,所以在过去,许多应用程序只能使用非常简单的加密技术,这样做的结果就是加密的数据很容易被人破译。而使用Microsoft提供的加密应用程序接口(即Cryp 阅读详情

相关推荐

MySQL与数据加密:保护敏感信息的安全

通过本文的学习,你现在应该了解了如何在 MySQL 中使用内置的加密函数来加密数据,以及如何在应用程序层使用 PHP 进行数据加密。此外,我们也介绍了如何使用 MySQL 的透明数据加密 (TDE) 来加密整个数据库或表空间。这些方法都可以帮助你更好地保护敏感信息。记住,数据加密只是数据保护的一部分,还需要配合其他安全措施,例如强密码策略、定期的安全审计和更新等。希望这篇文章能对你有所帮助,保护好你的数据,让它们安全无忧!下次见啦!👋别忘了,数据安全是每个人都应该关心的大事哦!

java专栏 4万+

数据加密技术

数据加密技术

2301_80823515的博客 1550

企名片数据加密javascript逆向实战

看完这篇JS逆向实战文章还没有一点思路?我教你啊

吴秋霖的博客 1万+

ASP.NET(C#)常用数据加密和解密方法汇总

应同事所邀把ASP.NET(C#)常用数据加密和解密方法列出供大家参考,特此发布出来,希望对大家有点帮助。数据虽来源于网络,系仰天一笑悉心整理。 ASP.NET(C#)常用数据加密和解密方法汇总  一、            数据加密的概念 1、  基本概念 2、  基本功能 3、  加密形式  二、            数据加密的项目应用和学习 1、  媒体加密:DRM 2、 ...

weixin_34210740的博客 1204

MEMS惯性传感器关键参数解析与误差优化策略

本文深入解析了MEMS惯性传感器的关键性能参数,如零偏稳定性、噪声与随机游走、振动整流误差等,并阐述了这些误差如何导致设备导航漂移、姿态不稳等问题。文章重点探讨了从硬件选型、系统设计到校准补偿、算法融合(如卡尔曼滤波)以及温度补偿等实战优化策略,旨在帮助工程师有效提升自动驾驶、无人机等设备的测量精度与稳定性。

weixin_28363123的博客 414

uniapp串口通信实战:从零搭建物联网设备控制App(附完整代码)

本文详细介绍了如何使用Uniapp实现串口通信,从零搭建物联网设备控制App。内容涵盖环境配置、串口初始化、数据收发、错误处理等核心功能,并提供了完整的代码示例,帮助开发者快速掌握跨平台串口通信技术,适用于智能农业、工业自动化等物联网场景。

weixin_30369041的博客 597

十种数据存储加密技术

原理解析部署位数据库UDF(User Defined Function)用户自定义函数是在已有数据库功能的基础上扩展更丰富的业务需求,其原理是在数据库支持的形式上,通过定义函数名称及执行过程,实现自定义的处理逻辑。UDF用户自定义函数加密,是通过UDF接口实现数据在数据库内的加解密。应用场景UDF用户自定义函数加密,作为一种在数据库侧的高灵活加解密集成方式,适用于某些数据库需要定制加解密的场景,尤其是实现基于国密算法的数据加解密。优势1、扩展能力强。

顺其自然~专栏 3529

[模型部署]-[LLM]昇腾部署Qwen3-Coder-30B-A3B-Instruct

摘要:本文介绍了在Ascend NPU上部署Qwen3-Coder-30B-A3B-Instruct大模型的实践过程。通过vLLM-Ascend框架,详细说明了环境准备(CANN 8.1、PyTorch-NPU 2.5.1等)、模型下载、容器启动及服务部署步骤,包括vLLM服务的启动参数配置和接口测试方法。测试结果显示在当前2卡910B3配置下性能表现仅为8token/s(1并发),并指出流式调用时存在无法输出usage信息的问题。该方案为Ascend平台私有化部署大模型推理服务提供了参考实现。

1671

加密算法概述

加密算法概述

liu_yp_的博客 2525

如何用Python实现SPEI指数计算?从数据准备到结果可视化完整指南

本文提供了一份完整的Python实现SPEI指数计算指南,涵盖从数据准备、潜在蒸散量计算到结果可视化的全流程。详细介绍了使用Thornthwaite方法计算PET、拟合三参数log-logistic分布以及标准化转换的核心算法,并提供了模块化代码和可视化方案,帮助用户构建可复用的干旱分析工具。

cola5的博客 267

ADRV9009学习资料保存:基于XC7Z100+ADRV9009的双收双发无线电射频板卡

ADRV9009学习资料保存:基于XC7Z100+ADRV9009的双收双发无线电射频板卡 一、板卡概述 基于XC7Z100+ADRV9009的双收双发无线电射频板卡是基于XilinxZYNQFPGA和ADI的无线收发芯片ADRV9009开发的专用功能板卡,用于5G小基站,无线图传,数据收发...

9364

MySQL 数据加密技术分享

数据加密是保护数据机密性的关键手段,MySQL提供了多种加密方式,包括透明数据加密(TDE)、列级加密、文件系统加密和SSL/TLS加密。TDE对整个数据库文件进行加密,对应用程序透明,但可能带来性能开销和密钥管理问题。列级加密则针对特定列的数据,提供更高的灵活性。选择合适的加密方式需根据业务场景和安全需求,同时需考虑性能、密钥管理和备份恢复等因素。MySQL支持多种加密算法,如AES和RSA,并可通过监控工具跟踪加密状态。有效的数据加密策略能显著提升数据安全性,满足合规要求。

unicrom的博客 1716

国产大模型 coding plan 实战决策指南:GLM、Kimi、豆包、abab 四大模型分层选型与工程落地

大模型辅助编程(coding assistant)正从概念验证走向规模化工程落地,其核心已不再是‘能否生成代码’,而是‘如何在真实开发流程中精准赋能’。理解模型能力边界、匹配技术栈特征、构建分层工作流(L1行级补全/L2函数生成/L3模块重构),是实现稳定提效的关键。GLM系列以工程稳定性见长,适合代码审计与测试生成;Kimi-Max凭借200K超长上下文胜任深度重构与合规审查;豆包响应快、框架适配深,是IDE高频补全的理想选择;abab系列则在IoT固件等跨模态场景中展现独特价值。本文聚焦国产模型在金融、

weixin_32238157的博客 427

数据加密原理详解

数据加密,是一门历史悠久的技术,指通过加密算法和加密密钥将明文转变为密文,而解密则是通过解密算法和解密密钥将密文恢复为明文。它的核心是密码学。 数据加密仍是计算机系统对信息进行保护的一种最可靠的办法。它利用密码技术对信息进行加密,实现信息隐蔽,从而起到保护信息的安全的作用。 一、基本信息 简介 和防火墙配合使用的数据加密技术,是为提高信息系统和数据的安全性和保密性,防止秘密数据被外部破译而采用的主...

you_ranxi的博客 1万+

第3.4章 机器人第三方库实战总结(四):G2O优化库从入门到实战(附SLAM实例代码)

自定义边同样是满足复杂应用需求的重要手段。自定义边时,需要明确边所连接的顶点类型以及边所表示的误差项的计算方式。假设我们要定义一条边,用于约束两个上述自定义顶点之间的相对位姿和传感器偏移量关系。我们可以这样定义边类:public:// 计算误差// 计算雅可比矩阵// 读盘和存盘函数,这里暂不实现。

行知SLAM 358

高通Camx功能feature分析之一:remosaic功能导通

本文详细介绍了S5K3P9S传感器前置场景中SW Remosaic功能的实现流程。首先需在sensorxml中确认支持SW Remosaic类型,并集成remosaic相关库文件(libremosaic_wrapper.so等)。核心实现包括:初始化阶段调用InitFrontSamsungRemosaic();执行线程DeferFrontInitThread()读取校准数据;通过DoSamsungRemosaic()执行remosaic算法处理;最后在析构函数中调用DeinitFrontSamsungRem

1700

数据脱敏和数据加密的区别

数据脱敏和数据加密是两种截然不同的技术,适用于不同目的。 脱敏技术主要是为了兼顾数据安全与数据使用,采用的是专业的数据脱敏算法;而加密则是通过对数据进行编码来保护数据,检索原始值的唯一方法是使用解密密钥解码数据。 脱敏数据仍然便于使用,但加密数据不是。 加密的主要优点在于它的可逆性,但是解密密钥存储位置、如何存储以及确定谁具有访问权限等工作都会给整个安全工作增加额外的成本、故障点,加剧复杂性...

kkx1988的博客 3万+

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

数据加密方案

1 什么是数据加密 1.1 数据加密的定义 数据加密又称密码学,它是一门历史悠久的技术,指通过加密算法和加密密钥将明文转变为密文,而解密则是通过解密算法和解密密钥将密文恢复为明文。数据加密目前仍是计算机系统对信息进行保护的一种最可靠的办法。它利用密码技术对信息进行加密,实现信息隐蔽,从而起到保护信息的安全的作用。 1.2 加密方式分类 数据加密技术要求只有在指定的用户或网络下,才能解除密码而获得原来的数据,这就需要给数据发送方和接受方以一些特殊的信息用于加解密,这就是所谓的密钥。其密钥的值是从大量的随

ourLang 9879

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

数据加密:Redis数据加密与解密

1.背景介绍 Redis是一个开源的高性能键值存储系统,它支持数据的持久化,不仅仅支持简单的键值对,还提供列表、集合、有序集合和映射等数据结构的存储。Redis支持数据的备份、恢复和同步,并且支持数据的压缩。Redis还提供了Pub/Sub消息通信模式,可以用于构建实时Web应用程序。 Redis是一个非关系型数据库,它的数据存储结构是基于内存的。因此,它的读写速度非常快,通常可以达到1000...

AI天才研究院 1124

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

MySQL 数据加密

mysql数据加密

大黄鸭在发光的专栏 2003

Unity 数据加密之 AES

在Unity游戏开发中,数据加密是保护游戏数据安全、防止作弊和破解的重要手段。本文将介绍对称加密算法(AES)的使用。

qq_44809934的博客 1589

ShardingSphere 实践(7)—— 数据加密

ShardingSphere 数据加密:功能详解、实现细节、用例测试

wzy0623的专栏 4357

数据加密简介

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 数据加密的主要方式 前言 2022年3月开始接触加密接口测试,记录下常用数据加密方式 一、数据加密方式主要有两种“对称加密”和“非对称加密” 1、对称式加密 对称式加密就是加密和解密使用同一个秘钥,通常称之为“Session Key”,这种加密技术目前被广泛采用,如美国政府所采用的的DES加密标准就是一种典型的“对称式”加密法,它的Session Key长度为56Bits。 2、非对称式加密 非对称式加密就是加密和解密所使用的的不是同.

测试指南 1万+

SQL Server 数据加密功能解析

数据加密是被破解、物理介质被盗、备份被窃取的最后一道防线,数据加密,一方面解决数据被窃取安全问题,另一方面有关法律要求强制加密数据。的数据加密相较于其他数据库,功能相对完善,加密方法较多。通常来讲,数据加密分为对称加密和非对称加密。对称加密:加密与解密使用同一密钥,密钥需要传输,安全性较弱,但性能较非对称要好。非对称加密:加密与解密使用不同密钥(公钥和私钥),较对称密钥安全性较好,但是算法较复杂,带来性能上的损失。因此,折中的方法是使用对称密钥加密数据,使用非对称密钥加密对称密钥。

2301_78008478的博客 3097
上一篇: RPC简介及框架选择
下一篇: 订单一定时间未支付-回仓(Timer实现)
jack_too
博客等级 码龄9年 17粉丝 32原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值