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

加密与安全_使用Java代码操作RSA算法生成的密钥对

文章目录

  • Pre
  • 概述
    • 什么是非对称加密算法?
    • 如何工作?
    • 示例:RSA算法
    • 特点和优势
    • ECC:另一种非对称加密算法
  • Code
    • 生成公钥和私钥
    • 私钥加密
    • 私钥加密私钥解密 ( 行不通 )
    • 私钥加密公钥解密
    • 公钥加密和公钥解密 (行不通)
    • 保存公钥和私钥
    • 读取私钥
    • 读取公钥
    • 使用读取的公钥加密,私钥解密
  • Source

在这里插入图片描述


Pre

加密与安全_探索非对称加密算法_RSA算法


概述

在数字化时代,网络通信的安全性是必须关注的重要问题之一。非对称加密算法作为现代密码学的重要组成部分,为保护通信的隐私提供了一种可靠的解决方案。


什么是非对称加密算法?

非对称加密算法,又称为公钥加密算法,是一种密码学中的重要概念。它与传统的对称加密算法不同,需要一对密钥:公钥和私钥。这对密钥之间存在着特殊的数学关系,但无法通过公钥推导出私钥,从而保证了通信的安全性。

如何工作?

当发送方A希望将数据发送给接收方B时,A可以使用B的公钥对数据进行加密,得到密文。只有拥有对应私钥的B才能解密这个密文。同样地,B也可以使用A的公钥加密数据,只有A持有私钥才能解密。这种加密和解密使用不同的密钥的特点,使得非对称加密算法成为了保护通信隐私的重要工具。

示例:RSA算法

RSA算法是非对称加密算法中最常见的一种,它利用了大数分解的数学难题,保证了通信的安全性。在RSA算法中,公钥是公开的,私钥是保密的。发送方使用接收方的公钥对数据进行加密,而接收方使用自己的私钥进行解密,从而实现了安全的通信。

特点和优势

  • 加密和解密使用不同的密钥,提高了通信的安全性。
  • 如果使用私钥加密,只能使用公钥解密;反之亦然。
  • 非对称加密算法安全性高,但处理数据速度较慢。

ECC:另一种非对称加密算法

除了RSA算法,还有一种备受关注的非对称加密算法,即椭圆曲线密码学(ECC)。ECC利用了椭圆曲线上的数学难题,相比RSA算法,它能够以更短的密钥长度实现相当于甚至更高的安全级别,同时在资源受限的环境下拥有更好的性能表现。


Code

生成公钥和私钥

package com.artisan;import com.sun.org.apache.xml.internal.security.utils.Base64;import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;/*** @author 小工匠* @version 1.0 */
public class RsaKeyPair {public static void main(String[] args) throws Exception {// 指定加密算法为RSAString algorithm = "RSA";// 创建密钥对生成器对象KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(algorithm);// 生成RSA密钥对KeyPair keyPair = keyPairGenerator.generateKeyPair();// 获取生成的私钥PrivateKey privateKey = keyPair.getPrivate();// 获取生成的公钥PublicKey publicKey = keyPair.getPublic();// 获取私钥的编码字节数组byte[] privateKeyEncoded = privateKey.getEncoded();// 获取公钥的编码字节数组byte[] publicKeyEncoded = publicKey.getEncoded();// 对公私钥的编码字节数组进行Base64编码String privateKeyString = Base64.encode(privateKeyEncoded);String publicKeyString = Base64.encode(publicKeyEncoded);// 打印私钥的Base64编码字符串System.out.println(privateKeyString);System.out.println("----------------------------------");// 打印公钥的Base64编码字符串System.out.println(publicKeyString);}
}

使用RSA算法生成一个密钥对,并将私钥和公钥进行Base64编码后打印出来了。

在这里插入图片描述


私钥加密

package com.artisan;import com.sun.org.apache.xml.internal.security.utils.Base64;import javax.crypto.Cipher;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;/*** @author 小工匠* @version 1.0* @mark: 显示代码,改变世界*/
public class PrivateKeyEnc {public static void main(String[] args) throws Exception {String input = "小工匠的IT生活";// 指定加密算法为RSAString algorithm = "RSA";// 创建密钥对生成器对象KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(algorithm);// 生成RSA密钥对KeyPair keyPair = keyPairGenerator.generateKeyPair();// 获取生成的私钥PrivateKey privateKey = keyPair.getPrivate();// 获取生成的公钥PublicKey publicKey = keyPair.getPublic();// 获取私钥的编码字节数组byte[] privateKeyEncoded = privateKey.getEncoded();// 获取公钥的编码字节数组byte[] publicKeyEncoded = publicKey.getEncoded();// 对公私钥的编码字节数组进行Base64编码String privateKeyString = Base64.encode(privateKeyEncoded);String publicKeyString = Base64.encode(publicKeyEncoded);// 打印生成的密钥对System.out.println("私钥(Base64编码): " + privateKeyString);System.out.println("公钥(Base64编码): " + publicKeyString);// 创建加密对象,参数表示加密算法Cipher cipher = Cipher.getInstance(algorithm);// 初始化加密对象// 第一个参数:加密模式// 第二个参数:使用私钥进行加密cipher.init(Cipher.ENCRYPT_MODE, privateKey);// 使用私钥加密输入的字符串byte[] encryptedBytes = cipher.doFinal(input.getBytes());// 对加密后的字节数组进行Base64编码,并打印System.out.println("加密后的字符串(Base64编码): " + Base64.encode(encryptedBytes));}
}

私钥加密私钥解密 ( 行不通 )

在上面的代码上追加

// 私钥进行解密 (错误的演示)
cipher.init(Cipher.DECRYPT_MODE,privateKey);// 对密文进行解密,不需要使用base64,因为原文不会乱码byte[] bytes1 = cipher.doFinal(encryptedBytes);System.out.println(new String(bytes1));

在这里插入图片描述


私钥加密公钥解密

将上述代码的 私钥解密,换成使用公钥解密

// 公钥进行解密
cipher.init(Cipher.DECRYPT_MODE,publicKey);
// 对密文进行解密,不需要使用base64,因为原文不会乱码
byte[] bytes1 = cipher.doFinal(encryptedBytes);
System.out.println("解密后的字符串: " + new String(bytes1));

在这里插入图片描述


公钥加密和公钥解密 (行不通)

在这里插入图片描述

在这里插入图片描述


保存公钥和私钥

生成RSA非对称加密算法的密钥对,并将生成的公钥和私钥保存在本地文件中。

package com.artisan;import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import org.apache.commons.io.FileUtils;import java.io.File;
import java.nio.charset.Charset;
import java.security.*;public class KeyPairOperate {public static void main(String[] args) throws Exception {// 加密算法String algorithm = "RSA";// 生成密钥对并保存在本地文件中generateKeyToFile(algorithm, "a.pub", "a.pri");}/*** 生成密钥对并保存在本地文件中** @param algorithm : 算法* @param pubPath   : 公钥保存路径* @param priPath   : 私钥保存路径* @throws Exception*/private static void generateKeyToFile(String algorithm, String pubPath, String priPath) throws Exception {// 获取密钥对生成器KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(algorithm);// 获取密钥对KeyPair keyPair = keyPairGenerator.generateKeyPair();// 获取公钥PublicKey publicKey = keyPair.getPublic();// 获取私钥PrivateKey privateKey = keyPair.getPrivate();// 获取byte数组byte[] publicKeyEncoded = publicKey.getEncoded();byte[] privateKeyEncoded = privateKey.getEncoded();// 进行Base64编码String publicKeyString = Base64.encode(publicKeyEncoded);String privateKeyString = Base64.encode(privateKeyEncoded);// 保存文件FileUtils.writeStringToFile(new File(pubPath), publicKeyString, Charset.forName("UTF-8"));FileUtils.writeStringToFile(new File(priPath), privateKeyString, Charset.forName("UTF-8"));}
}

在这里插入图片描述


读取私钥

// 读取私钥
PrivateKey privateKey = readPrivateKeyFromFile(algorithm, "a.pri");byte[] encoded = privateKey.getEncoded();String privateContent = Base64.encode(encoded);System.out.println("私钥内容:" + privateContent);
 /*** @param algorithm* @param filePath* @return* @throws Exception*/private static PrivateKey readPrivateKeyFromFile(String algorithm, String filePath) throws Exception {// 从文件中读取私钥字符串String privateKeyString = FileUtils.readFileToString(new File(filePath), StandardCharsets.UTF_8);// 进行Base64解码byte[] privateKeyEncoded = Base64.decode(privateKeyString);// 获取密钥工厂KeyFactory keyFactory = KeyFactory.getInstance(algorithm);// 构建密钥规范 进行Base64解码PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(Base64.decode(privateKeyString));return keyFactory.generatePrivate(spec);}

在这里插入图片描述
看下生成的文件中的内容:

在这里插入图片描述


读取公钥

// 读取公钥
PublicKey publicKey = readPublicKeyFromFile(algorithm, "a.pub");byte[] publicKeyEncoded = publicKey.getEncoded();
String publicContent = Base64.encode(publicKeyEncoded);
System.out.println("公钥内容:" + publicContent);
 /*** @param algorithm* @param filePath* @return* @throws Exception*/private static PublicKey readPublicKeyFromFile(String algorithm, String filePath) throws Exception {// 将文件内容转为字符串String publicKeyString = FileUtils.readFileToString(new File(filePath), StandardCharsets.UTF_8);// 获取密钥工厂KeyFactory keyFactory = KeyFactory.getInstance(algorithm);// 构建密钥规范 进行Base64解码X509EncodedKeySpec spec = new X509EncodedKeySpec(Base64.decode(publicKeyString));// 生成公钥return keyFactory.generatePublic(spec);}

在这里插入图片描述

在这里插入图片描述


使用读取的公钥加密,私钥解密

// 使用公钥私钥实现加解密
String text = "小工匠的IT生活";
System.out.println("原文:" + text);String enc = encryptRSA(algorithm, publicKey, text);
System.out.println("公钥加密后的数据:" + enc);String plainText = decryptRSA(algorithm, privateKey, enc);
System.out.println("私钥解密后的数据:" + plainText);
 /*** 解密数据** @param algorithm : 算法* @param encrypted : 密文* @param key       : 密钥* @return : 原文* @throws Exception*/public static String decryptRSA(String algorithm, Key key, String encrypted) throws Exception {// 创建加密对象// 参数表示加密算法Cipher cipher = Cipher.getInstance(algorithm);// 私钥进行解密cipher.init(Cipher.DECRYPT_MODE, key);// 由于密文进行了Base64编码, 在这里需要进行解码byte[] decode = Base64.decode(encrypted);// 对密文进行解密,不需要使用base64,因为原文不会乱码byte[] bytes1 = cipher.doFinal(decode);return new String(bytes1);}/*** 使用密钥加密数据** @param algorithm : 算法* @param input     : 原文* @param key       : 密钥* @return : 密文* @throws Exception*/public static String encryptRSA(String algorithm, Key key, String input) throws Exception {// 创建加密对象// 参数表示加密算法Cipher cipher = Cipher.getInstance(algorithm);// 初始化加密// 第一个参数:加密的模式// 第二个参数:使用私钥进行加密cipher.init(Cipher.ENCRYPT_MODE, key);// 私钥加密byte[] bytes = cipher.doFinal(input.getBytes());// 对密文进行Base64编码return Base64.encode(bytes);}

在这里插入图片描述


Source

package com.artisan;import com.sun.org.apache.xml.internal.security.utils.Base64;
import org.apache.commons.io.FileUtils;import javax.crypto.Cipher;
import java.io.File;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;/*** @author 小工匠* @version 1.0* @mark: show me the code , change the world*/
public class KeyPairOperate {public static void main(String[] args) throws Exception {// 加密算法String algorithm = "RSA";// 生成密钥对并保存在本地文件中generateKeyToFile(algorithm, "a.pub", "a.pri");// 读取私钥PrivateKey privateKey = readPrivateKeyFromFile(algorithm, "a.pri");byte[] encoded = privateKey.getEncoded();String privateContent = Base64.encode(encoded);System.out.println("私钥内容:" + privateContent);// 读取公钥PublicKey publicKey = readPublicKeyFromFile(algorithm, "a.pub");byte[] publicKeyEncoded = publicKey.getEncoded();String publicContent = Base64.encode(publicKeyEncoded);System.out.println("公钥内容:" + publicContent);// 使用公钥私钥实现加解密String text = "小工匠的IT生活";System.out.println("原文:" + text);String enc = encryptRSA(algorithm, publicKey, text);System.out.println("公钥加密后的数据:" + enc);String plainText = decryptRSA(algorithm, privateKey, enc);System.out.println("私钥解密后的数据:" + plainText);}/*** 解密数据** @param algorithm : 算法* @param encrypted : 密文* @param key       : 密钥* @return : 原文* @throws Exception*/public static String decryptRSA(String algorithm, Key key, String encrypted) throws Exception {// 创建加密对象// 参数表示加密算法Cipher cipher = Cipher.getInstance(algorithm);// 私钥进行解密cipher.init(Cipher.DECRYPT_MODE, key);// 由于密文进行了Base64编码, 在这里需要进行解码byte[] decode = Base64.decode(encrypted);// 对密文进行解密,不需要使用base64,因为原文不会乱码byte[] bytes1 = cipher.doFinal(decode);return new String(bytes1);}/*** 使用密钥加密数据** @param algorithm : 算法* @param input     : 原文* @param key       : 密钥* @return : 密文* @throws Exception*/public static String encryptRSA(String algorithm, Key key, String input) throws Exception {// 创建加密对象// 参数表示加密算法Cipher cipher = Cipher.getInstance(algorithm);// 初始化加密// 第一个参数:加密的模式// 第二个参数:使用私钥进行加密cipher.init(Cipher.ENCRYPT_MODE, key);// 私钥加密byte[] bytes = cipher.doFinal(input.getBytes());// 对密文进行Base64编码return Base64.encode(bytes);}/*** @param algorithm* @param filePath* @return* @throws Exception*/private static PublicKey readPublicKeyFromFile(String algorithm, String filePath) throws Exception {// 将文件内容转为字符串String publicKeyString = FileUtils.readFileToString(new File(filePath), StandardCharsets.UTF_8);// 获取密钥工厂KeyFactory keyFactory = KeyFactory.getInstance(algorithm);// 构建密钥规范 进行Base64解码X509EncodedKeySpec spec = new X509EncodedKeySpec(Base64.decode(publicKeyString));// 生成公钥return keyFactory.generatePublic(spec);}/*** @param algorithm* @param filePath* @return* @throws Exception*/private static PrivateKey readPrivateKeyFromFile(String algorithm, String filePath) throws Exception {// 从文件中读取私钥字符串String privateKeyString = FileUtils.readFileToString(new File(filePath), StandardCharsets.UTF_8);// 进行Base64解码byte[] privateKeyEncoded = Base64.decode(privateKeyString);// 获取密钥工厂KeyFactory keyFactory = KeyFactory.getInstance(algorithm);// 构建密钥规范 进行Base64解码PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(Base64.decode(privateKeyString));return keyFactory.generatePrivate(spec);}/*** 生成密钥对并保存在本地文件中** @param algorithm : 算法* @param pubPath   : 公钥保存路径* @param priPath   : 私钥保存路径* @throws Exception*/private static void generateKeyToFile(String algorithm, String pubPath, String priPath) throws Exception {// 获取密钥对生成器KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(algorithm);// 获取密钥对KeyPair keyPair = keyPairGenerator.generateKeyPair();// 获取公钥PublicKey publicKey = keyPair.getPublic();// 获取私钥PrivateKey privateKey = keyPair.getPrivate();// 获取byte数组byte[] publicKeyEncoded = publicKey.getEncoded();byte[] privateKeyEncoded = privateKey.getEncoded();// 进行Base64编码String publicKeyString = Base64.encode(publicKeyEncoded);String privateKeyString = Base64.encode(privateKeyEncoded);// 保存文件FileUtils.writeStringToFile(new File(pubPath), publicKeyString, Charset.forName("UTF-8"));FileUtils.writeStringToFile(new File(priPath), privateKeyString, Charset.forName("UTF-8"));}
}

在这里插入图片描述

相关文章:

加密与安全_使用Java代码操作RSA算法生成的密钥对

文章目录 Pre概述什么是非对称加密算法?如何工作?示例:RSA算法特点和优势ECC:另一种非对称加密算法 Code生成公钥和私钥私钥加密私钥加密私钥解密 ( 行不通 )私钥加密公钥解密公钥加密和公钥解密 (行不通)保…...

Spring Boot中实现图片上传功能的两种策略

🌟 前言 欢迎来到我的技术小宇宙!🌌 这里不仅是我记录技术点滴的后花园,也是我分享学习心得和项目经验的乐园。📚 无论你是技术小白还是资深大牛,这里总有一些内容能触动你的好奇心。🔍 &#x…...

07.axios封装实例

一.简易axios封装-获取省份列表 1. 需求:基于 Promise 和 XHR 封装 myAxios 函数,获取省份列表展示到页面 2. 核心语法: function myAxios(config) {return new Promise((resolve, reject) > {// XHR 请求// 调用成功/失败的处理程序}) …...

【Linux】第四十一站:线程控制

一、Linux线程VS进程 1.进程和线程 进程是资源分配的基本单位线程是调度的基本单位线程共享进程数据,但也拥有自己的一部分数据:线程ID一组寄存器(上下文)栈errno信号屏蔽字调度优先级 2.进程的多个线程共享 同一地址空间,因此Text Segment、…...

ChatGPT提示词工程:prompt和chatbot

ChatGPT Prompt Engineering for Developers 本文是 https://www.deeplearning.ai/short-courses/chatgpt-prompt-engineering-for-developers/ 这门课程的学习笔记。 ChatGPT提示词工程:prompt和chatbot 文章目录 ChatGPT Prompt Engineering for DevelopersWhat …...

java算法

常见的七种查找算法: 数据结构是数据存储的方式,算法是数据计算的方式。所以在开发中,算法和数据结构息息相关。 1. 基本查找 也叫做顺序查找 说明:顺序查找适合于存储结构为数组或者链表。 基本思想:顺序查找也称…...

铭文资产是比特币生态破局者 or 短暂热点?

比特币作为加密货币的鼻祖,一直以来都扮演着数字资产市场的引领者角色。最近几年,随着 BRC20 项目的兴起,我们看到了更多与比特币相互关联的创新。在比特币生态中,BRC20 项目不仅仅是数字资产的代表,更是一种对于区块链…...

Java基础 - 8 - 算法、正则表达式、异常

一. 算法 什么是算法? 解决某个实际问题的过程和方法 学习算法的技巧? 先搞清楚算法的流程,再直接去推敲如何写算法 1.1 排序算法 1.1.1 冒泡排序 每次从数组中找出最大值放在数组的后面去 public class demo {public static void main(S…...

gRPC-第二代rpc服务

在如今云原生技术的大环境下,rpc服务作为最重要的互联网技术,蓬勃发展,诞生了许多知名基于rpc协议的框架,其中就有本文的主角gRPC技术。 一款高性能、开源的通用rpc框架 作者作为一名在JD实习的Cpper,经过一段时间的学…...

Node.js是什么?

概念:Node.js1运行在服务器端的js,用来编写服务器 特点:单线程、异步、非阻塞、统一API 是一个构建在V8引擎之上的js运行环境,它使得js可以运行在浏览器以外的地方,相对于大部分的服务器端语言来说,Node.J…...

java SSM厂房管理系统myeclipse开发mysql数据库springMVC模式java编程计算机网页设计

一、源码特点 java SSM厂房管理系统是一套完善的web设计系统(系统采用SSM框架进行设计开发,springspringMVCmybatis),对理解JSP java编程开发语言有帮助,系统具有完整的源代码和数据库,系统主要采用B/S…...

uniapp实现---类似购物车全选

目录 一、实现思路 二、实现步骤 ①view部分展示 ②JavaScript 内容 ③css中样式展示 三、效果展示 四、小结 注意事项 一、实现思路 点击商家复选框,可选中当前商家下的所有商品。点击全选,选中全部商家的商品 添加单个多选框,在将多选…...

Java:List列表去重有序和无序

目录 待去重列表HashSet去重(不保证顺序)TreeSet去重(不保证顺序)LinkedHashSet去重(保证顺序)遍历List去重(保证顺序)Java8中Stream流处理(保证顺序)参考文章 待去重列表 // 列表 …...

Python绘图-12地理数据可视化

Matplotlib 自 带 4 类别 地理投影: Aitoff, Hammer, Mollweide 及 Lambert 投影,可以 结 合以下四 张 不同 的 图 了解四 种 不同投影 区别 。 12.1Aitoff投影 12.1.1图像呈现 12.1.2绘图代码 import numpy as np # 导入numpy库,用于…...

NineData与OceanBase完成产品兼容认证,共筑企业级数据库新生态

近日,云原生智能数据管理平台 NineData 和北京奥星贝斯科技有限公司的 OceanBase 数据库完成产品兼容互认证。经过严格的联合测试,双方软件完全相互兼容、功能完善、整体运行稳定且性能表现优异。 此次 NineData 与 OceanBase 完成产品兼容认证&#xf…...

旅游专业VR虚拟仿真情景教学实训

一、生动的情景模拟 VR技术能够创建出高度逼真的虚拟环境,使学生能够身临其境地体验旅游场景。无论是古色古香的古代建筑,还是充满异国情调的热带雨林,亦或是繁华的都市风光,VR都能一一呈现。这种沉浸式的体验,使得学…...

解决方案TypeError: string indices must be integers

文章目录 一、现象:二、解决方案 一、现象: PyTorch深度学习框架,运行bert-mini,本地环境是torch1.4-gpu,发现报错显示:TypeError: string indices must be integers 后面报字符问题,百度过找…...

【论文阅读】Segment Anything论文梳理

Abstract 我们介绍了Segment Anything(SA)项目:新的图像分割任务、模型和数据集。高效的数据循环采集,使我们建立了迄今为止最大的分割数据集,在1100万张图像中,共超过10亿个掩码。 该模型被设计和训练为可…...

接口自动化测试框架搭建:基于python+requests+pytest+allure实现

众所周知,目前市面上大部分的企业实施接口自动化最常用的有两种方式: 1、基于代码类的接口自动化,如: PythonRequestsPytestAllure报告定制 2、基于工具类的接口自动化,如: PostmanNewmanJenkinsGit/svnJme…...

蓝桥杯(3.9)

1210. 连号区间数 蓝桥杯暴力过80% import java.util.Arrays; import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc new Scanner(System.in);int n sc.nextInt();int[] res new int[n];int[] copy new int[n];for(int i0;i&…...

零门槛NAS搭建:WinNAS如何让普通电脑秒变私有云?

一、核心优势:专为Windows用户设计的极简NAS WinNAS由深圳耘想存储科技开发,是一款收费低廉但功能全面的Windows NAS工具,主打“无学习成本部署” 。与其他NAS软件相比,其优势在于: 无需硬件改造:将任意W…...

边缘计算医疗风险自查APP开发方案

核心目标:在便携设备(智能手表/家用检测仪)部署轻量化疾病预测模型,实现低延迟、隐私安全的实时健康风险评估。 一、技术架构设计 #mermaid-svg-iuNaeeLK2YoFKfao {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg…...

Nuxt.js 中的路由配置详解

Nuxt.js 通过其内置的路由系统简化了应用的路由配置,使得开发者可以轻松地管理页面导航和 URL 结构。路由配置主要涉及页面组件的组织、动态路由的设置以及路由元信息的配置。 自动路由生成 Nuxt.js 会根据 pages 目录下的文件结构自动生成路由配置。每个文件都会对…...

【论文阅读28】-CNN-BiLSTM-Attention-(2024)

本文把滑坡位移序列拆开、筛优质因子,再用 CNN-BiLSTM-Attention 来动态预测每个子序列,最后重构出总位移,预测效果超越传统模型。 文章目录 1 引言2 方法2.1 位移时间序列加性模型2.2 变分模态分解 (VMD) 具体步骤2.3.1 样本熵(S…...

什么是Ansible Jinja2

理解 Ansible Jinja2 模板 Ansible 是一款功能强大的开源自动化工具,可让您无缝地管理和配置系统。Ansible 的一大亮点是它使用 Jinja2 模板,允许您根据变量数据动态生成文件、配置设置和脚本。本文将向您介绍 Ansible 中的 Jinja2 模板,并通…...

力扣-35.搜索插入位置

题目描述 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 请必须使用时间复杂度为 O(log n) 的算法。 class Solution {public int searchInsert(int[] nums, …...

NXP S32K146 T-Box 携手 SD NAND(贴片式TF卡):驱动汽车智能革新的黄金组合

在汽车智能化的汹涌浪潮中,车辆不再仅仅是传统的交通工具,而是逐步演变为高度智能的移动终端。这一转变的核心支撑,来自于车内关键技术的深度融合与协同创新。车载远程信息处理盒(T-Box)方案:NXP S32K146 与…...

AI语音助手的Python实现

引言 语音助手(如小爱同学、Siri)通过语音识别、自然语言处理(NLP)和语音合成技术,为用户提供直观、高效的交互体验。随着人工智能的普及,Python开发者可以利用开源库和AI模型,快速构建自定义语音助手。本文由浅入深,详细介绍如何使用Python开发AI语音助手,涵盖基础功…...

数学建模-滑翔伞伞翼面积的设计,运动状态计算和优化 !

我们考虑滑翔伞的伞翼面积设计问题以及运动状态描述。滑翔伞的性能主要取决于伞翼面积、气动特性以及飞行员的重量。我们的目标是建立数学模型来描述滑翔伞的运动状态,并优化伞翼面积的设计。 一、问题分析 滑翔伞在飞行过程中受到重力、升力和阻力的作用。升力和阻力与伞翼面…...

pycharm 设置环境出错

pycharm 设置环境出错 pycharm 新建项目,设置虚拟环境,出错 pycharm 出错 Cannot open Local Failed to start [powershell.exe, -NoExit, -ExecutionPolicy, Bypass, -File, C:\Program Files\JetBrains\PyCharm 2024.1.3\plugins\terminal\shell-int…...