Java安全——安全提供者

本文介绍了Java中的安全提供者机制,包括其在JavaCryptographyArchitecture中的角色、主要组件如Provider类、Service类和Algorithm类的功能,以及如何设置、选择和管理安全提供者以满足不同安全需求。
摘要由CSDN通过智能技术生成

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

![在这里插入图片描述](https://img-
blog.csdnimg.cn/473d3418271041ac925d15c26da97f27.png)

引擎类体系结构

在这里插入图片描述

在这里插入图片描述

学习计划安排


我一共划分了六个阶段,但并不是说你得学完全部才能上手工作,对于一些初级岗位,学到第三四个阶段就足矣~

这里我整合并且整理成了一份【282G】的网络安全从零基础入门到进阶资料包,需要的小伙伴可以扫描下方CSDN官方合作二维码免费领取哦,无偿分享!!!

如果你对网络安全入门感兴趣,那么你需要的话可以

点击这里👉网络安全重磅福利:入门&进阶全套282G学习资源包免费分享!

①网络安全学习路线
②上百份渗透测试电子书
③安全攻防357页笔记
④50份安全攻防面试指南
⑤安全红队渗透工具包
⑥HW护网行动经验总结
⑦100个漏洞实战案例
⑧安全大厂内部视频资源
⑨历年CTF夺旗赛题解析

  • 16
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值