Java安全——安全提供者

Java安全

安全提供者

在Java中,安全提供者(Security Provider)是一种实现了特定安全服务的软件模块。它提供了一系列的加密、解密、签名、验证和随机数生成等安全功能。安全提供者基础设施在Java中的作用是为开发人员提供一种扩展和替换标准安全功能的方式,以满足特定的安全需求。

Java的安全提供者基础设施是通过Java Cryptography Architecture(JCA)实现的。JCA定义了一组API和框架,用于在Java平台上实现各种安全服务。安全提供者是JCA的核心组件之一,它通过实现JCA规范中定义的接口,向应用程序提供安全功能。

安全提供者可以由Java平台提供的默认提供者,也可以是第三方开发的提供者。默认提供者包含在Java开发工具包(JDK)中,并提供了一些常见的加密算法和安全功能。第三方提供者则可以通过扩展JCA接口,实现自定义的加密算法和其他安全功能。

使用安全提供者,开发人员可以在应用程序中轻松地切换和配置不同的安全实现。例如,可以根据具体的安全需求选择不同的提供者,或者通过配置文件动态加载和替换提供者。这种灵活性使得Java应用程序能够适应不同的安全环境和要求。

总之,Java中的安全提供者基础设施允许开发人员使用标准或自定义的安全功能,以保护和加密数据,验证身份,以及执行其他与安全相关的操作。它为Java应用程序提供了一种可扩展和灵活的安全解决方案。

安全提供者体系结构

提供了两个概念的抽象:引擎和算法

  • 引擎

    • 安全提供者提供了操作,这些操作就是引擎的抽象
  • 算法

    • 算法如何具体执行,引擎的不同算法的实现
  • 消息摘要就是一个引擎,是程序员所能执行的一个操作

  • 消息摘要的操作是与具体计算算法无关的

安全提供者体系结构中的组件

Java安全提供者Provider体系结构中涉及到的主要组件包括以下几个方面:

  1. Provider类

Provider类是Java安全API提供商的实现类。它们实现了Java提供的标准接口,并提供了一组安全算法实现。每个Provider类都有一个唯一的名称,用于标识它们在Java运行时环境中的身份。开发人员可以通过API或者配置文件指定使用哪一个Provider类来实现相应的安全功能。

  1. Service类

Service类是Provider类的组成部分,它是实现特定算法的类。Service类提供了各种算法的实现,包括加密、签名、哈希等。Service类还提供了一组支持该算法的参数和属性。

  1. Algorithm类

Algorithm类是Java安全API提供的加密算法、哈希算法、签名算法等的抽象基类。它定义了与特定算法相关的所有方法和属性,以及与该算法相关的所有参数和属性。

  1. Key类

Key类是Java安全API提供的密钥的抽象基类。它定义了生成和管理密钥的所有方法和属性。开发人员可以使用Key类来创建、存储、和翻译密钥。

  1. Certificate类

Certificate类是Java安全API提供的证书的抽象基类。它定义了数字证书的结构和内容。开发人员可以使用Certificate类来创建、处理、验证数字证书。


In the architecture of the security provider (provider) in Java security, there are several key components:

  1. Provider: A provider is an implementation of the java.security.Provider class. It is responsible for providing specific security services, such as cryptographic algorithms, key management, secure random number generation, and more. Each provider has a unique name and can be registered and used by the Java security framework.
  2. Service: A service represents a specific security functionality provided by a provider. It is implemented as a subclass of the java.security.Provider.Service class. Examples of services include encryption algorithms, digital signature algorithms, key generators, and secure random number generators.
  3. Algorithm: An algorithm is a specific implementation of a cryptographic operation or security function. It is identified by a unique name and is provided by a service within a provider. For example, the “AES” algorithm is a specific implementation of the Advanced Encryption Standard.
  4. Key: A key is a piece of information used in cryptographic operations, such as encryption, decryption, signing, or verification. Keys can be generated, stored, and managed by the security provider. Examples of keys include symmetric encryption keys, asymmetric encryption keys (public and private keys), and digital signature keys.
  5. Secure Random: Secure random number generation is crucial for many security operations. The secure random component of the provider generates cryptographically strong random numbers that are suitable for use in key generation, nonces, initialization vectors, and other security-related purposes.

These components work together to provide a comprehensive security infrastructure in Java. The provider offers various services with specific algorithms, and keys can be generated and managed by the provider. The secure random component ensures the generation of secure random numbers for cryptographic operations. Developers can utilize these components to build secure applications and implement various security functionalities.

安全提供者的选择

在这里插入图片描述

在这里插入图片描述

设置和选择查看

Java安全提供者的选择可以在启动JVM时通过指定系统属性java.security.provider来设置,例如:

java -Djava.security.provider=SunJCE ...

可以使用以下命令查看当前使用的安全提供者:

java -Djava.security.debug=provider -version

如果需要更改安全提供者,可以在代码中使用Security.insertProviderAt(provider, position)方法将指定的安全提供者插入到安全提供者列表的指定位置。如果不指定位置,则默认为列表的末尾。另外,也可以在JRE安全配置文件中更改默认的安全提供者列表。

在选择安全提供者时,需要根据具体的安全需求来选择,例如对称加密算法、非对称加密算法、消息摘要算法等。可以参考Java官方文档或第三方安全提供者的文档来选择合适的安全提供者。同时,还需要考虑安全提供者的性能、安全性和可靠性等因素。

Simply put

To set and view the security provider selection in Java, you can use the following methods:

  1. Setting the Security Provider:

    • Programmatically: You can set the security provider programmatically using the Security class. Use the Security.addProvider(Provider provider) method to add a provider to the list of available providers. The provider added first will be the default provider.
    • Configuration File: You can also set the security provider by modifying the java.security configuration file located in the JRE_HOME/lib/security directory. In this file, providers are listed in the order of preference. You can change the order or add/remove providers as per your requirements.
  2. Viewing the Security Provider:

    • Programmatically: You can use the Security class to view the list of installed providers and their preference order. The Security.getProviders() method returns an array of installed providers in the JVM.
    • Command Line: You can use the java.security.properties system property to view the security provider configuration. Run the command java -Djava.security.properties=<path_to_file> -jar <your_jar_file> to specify a custom properties file that contains the security provider configuration.
  3. Changing the Security Provider:

    • Programmatically: To change the security provider at runtime, you can remove the existing provider using the Security.removeProvider(String name) method and then add the desired provider using Security.addProvider(Provider provider) .
    • Configuration File: To change the security provider permanently, modify the java.security configuration file and reorder the providers as needed.
  4. Selecting the Security Provider:

    • By Default: If you don’t explicitly set the security provider, the JVM uses the default provider configured in the java.security file. This default provider is typically the first provider listed in the file.
    • Programmatically: If you want to select a specific provider programmatically, you can use the Security.setProperty(String key, String value) method to set the security.provider property to the desired provider’s name. This will override the default provider selection.

Remember that the exact steps and methods may vary depending on the Java version and implementation you are using. It’s recommended to consult the official Java documentation or relevant resources for your specific Java version.

Provider 类

Java安全提供者(Security Provider)是Java Security框架的核心组成部分之一,用于提供和管理加密算法、公钥证书、密钥库等安全相关的服务。

Provider类是提供相关安全服务的实现类,每个Provider实现类都提供了多个算法的实现。在Java Security框架中,一个Provider类的对象可以包含多个同类型的算法实现(每个算法实现都实现了JCA架构规定的相应API)。例如,一个Provider对象可以同时包含多个MessageDigest算法的实现,每个实现具有不同的算法名称。当需要使用算法时,可以通过算法名称获取相应的算法实现。

使用Provider类创建Provider对象:

可以通过以下方式获取Provider对象:

  1. 根据名字获取:
Provider provider = Security.getProvider("BC");
  1. 根据类名获取:
Provider provider = Security.getProvider(BouncyCastleProvider.PROVIDER_NAME);

使用Provider类向Provider中添加算法实现:

  1. 在配置文件java.security中配置

可以通过修改jre/lib/security/java.security配置文件实现向Provider对象中添加算法实现。(以BC(BouncyCastle)Provider为例)

在java.security配置文件中添加如下配置:

security.provider.1=org.bouncycastle.jce.provider.BouncyCastleProvider
  1. 在代码中添加
Security.addProvider(new BouncyCastleProvider());

在代码中添加时,需要确保添加的Provider对象还没有添加到Provider列表中。还可以根据需求来指定提供者的优先级。

Provider类方法说明:

Provider类提供了许多方法,常用的方法如下:

  1. getName():

获取Provider对象的名字。

String name = provider.getName();
  1. getVersion():

获取Provider对象的版本号。

double version = provider.getVersion();
  1. getService():

通过类型和算法名获取提供者的服务。

Service service = provider.getService("Cipher","AES/CBC/PKCS5Padding");
  1. getServices():

获取Provider对象所有提供的服务。

Set<Service> services = provider.getServices();
  1. put():

向Provider对象中添加服务,该方法需要传入一个Service对象。

provider.put(new Service(provider,"Myalgo","MyAlgorithm",MyAlgorithm.class.getName(),null,null));

Provider类还提供了其他一些方法,如hashtable、枚举等等。具体可以查看Java API文档。

Security 类

  • 管理java程序中所要用到的提供者类。
  • 并且在安全提供者体系结构建立最后一个环节
看看安全提供者的保驾护航
public static void main(String[] args) {
        Provider[] providers = Security.getProviders();
        for(Provider provider : providers) {
            System.out.println("Provider: " + provider.getName() + " version " + provider.getVersion());
            for(Object service : provider.keySet()) {
                System.out.println("  Service: " + service);
            }
        }
    }
Security类和安全管理器

Security公共类调用要调用安全管理器方法,保证在不可信的类调用影响到虚拟机的时候能够进行干预处理。

在这里插入图片描述

引擎类体系结构

在这里插入图片描述

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/35256.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Java性能权威指南-总结26

Java性能权威指南-总结26 数据库性能的最佳实践异常日志 数据库性能的最佳实践 异常 Java的异常处理一直有代价高昂的坏名声。其代价确实比处理正常的控制流高一些&#xff0c;不过在大多数情况下&#xff0c;这种代价并不值得浪费精力去绕过。另一方面&#xff0c;因为异常处…

【面试】美团面试真题和答案

文章目录 前言1.线程池有几种实现方式&#xff1f;2.线程池的参数含义&#xff1f;3.锁升级的过程&#xff1f;4.i 如何保证线程安全&#xff1f;5.HashMap和ConcurrentHashMap有什么区别&#xff1f;6.Autowired和Resource区别&#xff1f;7.说说常用的设计模式8.Redis为什么这…

SpringBoot2+Vue2实战(十二)springboot一对一,一对多查询

新建数据库表 Course Data TableName("t_course") public class Course implements Serializable {private static final long serialVersionUID 1L;/*** id*/TableId(value "id", type IdType.AUTO)private Integer id;/*** 课程名称*/private String…

微信小程序制作 购物商城首页 【内包含源码】

1、实现效果 手机效果预览,这里的首页使用到了轮播图。页面图片数据可以替换成自己的数据。 2、开发者工具效果图 3、项目的目录结构 4、首页核心代码 4.1 index.js 这里用来存放数据,页面的数据。目前是假数据,也可以调用接口接收真实数据 // index.jsimport {request }…

【我的创作纪念日】关于某站的音频爬虫+GUI

文章目录 一、前言&机遇二、爬虫代码三、爬虫GUI四、文件打包五、结果展示未来可期 一、前言&机遇 许久没看私信内容&#xff0c;一上线就看到了官方的私信&#xff0c;我已经来到CSDN1024天啦&#xff01; 想到注册这个号的初衷是学习记录爬虫&#xff0c;后面渐渐变…

【计算机视觉 | 目标检测】arxiv 计算机视觉关于目标检测的学术速递(7 月 3 日论文合集)

文章目录 一、检测相关(9篇)1.1 Federated Ensemble YOLOv5 - A Better Generalized Object Detection Algorithm1.2 Zero-shot Nuclei Detection via Visual-Language Pre-trained Models1.3 Federated Object Detection for Quality Inspection in Shared Production1.4 Comp…

【数据科学和可视化】反思十年数据科学和可视化工具的未来

数据科学在过去十年中呈爆炸式增长&#xff0c;改变了我们开展业务的方式&#xff0c;并让下一代年轻人为未来的工作做好准备。但是这种快速增长伴随着对数据科学工作的不断发展的理解&#xff0c;这导致我们在如何使用数据科学从我们的大量数据中获得可操作的见解方面存在很多…

Django的数据库配置、生成(创建)过程、写入数据、查看数据的学习过程记录

目录 01-配置数据库信息02-安装Python的MySQL数据库驱动程序 mysqlclient03-安装Mysql&#xff0c;并启动Mysql04-定义Django的数据库模型(定义数据表-编写models.py文件)05-按照数据的配置生成数据库(执行迁移命令)05-01-生成迁移执行文件05-02-执行数据库模型迁移 06-查看数据…

git bash 命令行反应慢、卡顿

1. 在Windows11的电脑上安装了git 后&#xff0c;鼠标右键打开git bash here&#xff0c;打开窗口缓慢&#xff0c;输入命令也慢的要死&#xff0c;如果安装git的时候选择在桌面创建图标&#xff0c;通过桌面图标打开也是一样的 2. 最简单的ls 命令&#xff0c;都要停顿半秒 3.…

m4a音频格式转换器:让音频轻松换装

大家有没有遇到这样的情况——你下载了一个很酷的音频文件&#xff0c;但是播放设备却说“不认识”这个格式&#xff1f;别担心&#xff01;现在有个超级厉害的工具可以帮你解决这个问题&#xff0c;它就是m4a音频格式转换器&#xff01;它能让你的音频文件变身&#xff0c;适应…

TiDB(2):TiDB架构特性

1 TiDB 整体架构 TiDB 集群主要包括三个核心组件&#xff1a;TiDB Server&#xff0c;PD Server 和 TiKV Server。此外&#xff0c;还有用于解决用户复杂 OLAP 需求的 TiSpark 组件和简化云上部署管理的 TiDB Operator 组件。 架构图解 1.1 TiDB Server TiDB Server 负责接收…

技术服务企业缺成本票,所得税高怎么解决?可有良策?

技术服务企业缺成本票&#xff0c;所得税高怎么解决&#xff1f;可有良策&#xff1f; 《税筹顾问》专注于园区招商、企业税务筹划&#xff0c;合理合规助力企业节税&#xff01; 技术服务型企业最核心的价值就是为客户提供技术支撑&#xff0c;而这类型的企业在税务方面面临的…

CSRF漏洞复现

目录 CSRF产生的条件CSRF漏洞分类CSRF漏洞危害CSRF漏洞检测CSRF漏洞修复方案利用靶场CSRF-Minefield-V1.0漏洞复现 CSRF产生的条件 一、被攻击者在登陆了web网页&#xff0c;并且在本地生成了cookie 二、在cookie未过期的情况下&#xff0c;利用同一个浏览器访问了攻击者的页…

最新版Flink CDC MySQL同步Elasticsearch(一)

1.环境准备 首先我们要基于Flink CDC MySQL同步MySQL的环境基础上&#xff08;flink-1.17.1、Java8、MySQL8&#xff09;搭建Elasticsearch7-17-10和Kibana 7.17.10。笔者已经搭建好环境&#xff0c;这里不做具体演示了&#xff0c;如果需要Es的搭建教程情况笔者其他博客 注意…

JVM源码剖析之Java对象创建过程

关于 "Java的对象创建" 这个话题分布在各种论坛、各种帖子&#xff0c;文章的水平参差不齐。并且大部分仅仅是总结 "面试宝典" 的流程&#xff0c;小部分就是copy其他帖子&#xff0c;极少能看到拿源码作为论证。所以特意写下这篇文章。 版本信息如下&…

Eclipse显示层级目录结构(像IDEA一样)

有的小伙伴使用IDEA习惯了&#xff0c;可能进入公司里面要求使用eclipse&#xff0c;但是eclipse默认目录是并列显示&#xff0c;而不是层级显示。部分人用起来感觉十分不方便。我们可以更改一下设置。 1、打开eclipse&#xff0c;找到这里 2、选择PackagePresentation 3、选…

Github-提交PR指南

1. Fork你将要提交PR的repo 2. 将你fork下来的repo克隆到你的本地 git clone your_repo.git Cloning into ultralytics... remote: Enumerating objects: 8834, done. remote: Counting objects: 100% (177/177), done. remote: Compressing objects: 100% (112/112), done. …

第二步:STM32F407ZGT6资源介绍

1.1 STM32F407ZGT6资源描述 内核&#xff1a; 32位 高性能ARM Cortex-M4处理器 时钟&#xff1a;高达168M,实际还可以超屏一点点 支持FPU&#xff08;浮点运算&#xff09;和DSP指令 IO口&#xff1a; STM32F407ZGT6: 144引脚 114个IO 大部分IO口都耐5V(模拟通道除外) …

C# .NET 如何调用 SAP RFC 接口

1.分析传参结构 SAP 传参格式对应 .NET 参数格式 SAP 参数.NET 参数参数类型import(导入)——关联类型为数据元素Param单个变量参数import(导出)——关联类型为结构体Struct结构体tableTable表 下面是 SAP 对应参数类型&#xff1a; 2.web.config 配置 配置文件需要客户端…

win10安装pytorch GPU

我记得以前安装过深度学习库GPU版本&#xff0c; 需要安装cuda什么的&#xff0c;翻了下还真写过一篇win10安装tensorflow的文章&#xff0c;但是流程不止不详细&#xff0c;还不清晰。这次就再记录一遍 这次安装的是pytorch&#xff0c;这么多年似乎pytorch要逐渐统一深度学习…