仅在方法范围内使用特定的Java安全提供程序 [英] Using a specific Java security provider only in the scope of a method
问题描述
因此,我正在寻找仅在功能范围内使用安全提供程序的方法。我已经可以通过添加以下两行来做到这一点:(假设BouncyCastle是提供程序)
Security.addProvider(new org.bouncycastle .jce.provider.BouncyCastleProvider());
JcaPEMKeyConverter转换器= new JcaPEMKeyConverter()。setProvider( BC);
//使用转换器
做一些事情Security.removeProvider( BC);
所以我只想对JcaPEMKeyConverter使用BC,然后对其余的使用默认安全提供程序。 p>
是否有更好的方法?更优雅吗?自定义Java注释怎么样?这是个好方法吗?
Thx:)
如果仅希望在 JcaPEMKeyConverter
类使用 setProvider(java.security.Provider提供者)
而不是 setProvider(java.lang.String providerName)
如下:
JcaPEMKeyConverter转换器= new JcaPEMKeyConverter()。setProvider(new BouncyCastleProvider());
然后无需在安全提供程序列表中添加和删除提供程序,因此可以避免 Security.addProvider
和 Security.removeProvider
调用。
希望能帮上忙,
So I am looking ways to use a security provider only in the scope of a function. I can already do this by adding these two lines: (assume BouncyCastle is the provider)
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
// do some stuff with converter
Security.removeProvider("BC");
So i just want to use BC for JcaPEMKeyConverter and then for the rest use default security provider.
Is there a better way to do this? More elegantly? How about a custom java annotation, is that a good way ?
Thx :)
If you only want that the BouncyCastleProvider
are used in JcaPEMKeyConverter
class use setProvider(java.security.Provider provider)
instead of setProvider(java.lang.String providerName)
as follows:
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider(new BouncyCastleProvider());
Then there is no need to add and remove the provider on the security providers list, so you can avoid Security.addProvider
and Security.removeProvider
calls.
Hope it helps,
这篇关于仅在方法范围内使用特定的Java安全提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!