http://blog.antoine.li/index.php/2010/10/android-trusting-ssl-certificates/
我按照这个教程,一切似乎都很好(我没有在路上得到任何错误),但我又得到了
06-24 18:42:31.746: WARN/System.err(14807): javax.net.ssl.SSLException: Not trusted server certificate
06-24 18:42:31.756: WARN/System.err(14807): Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
06-24 18:42:31.766: WARN/System.err(14807): Caused by: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
Run Code Online (Sandbox Code Playgroud)
我在http://subdomain.domain.com上有SSL - RapidSSL.我下载了(单个)证书并将其插入密钥库.添加了myHttpClient但又一次,我无法使https工作.
有什么建议?
编辑:在桌面上一切都很好 - 我没有得到任何错误/警告.
我遇到了Diffie Hellman实现的问题.我正在使用此代码 http://www.java2s.com/Tutorial/Java/0490__Security/DiffieHellmanKeyAgreement.htm
这实际上是我正在阅读的一本书中的一个例子.但我无法理解为什么generateSecret()为每个人创造一个不同的钥匙KeyAgreement.我注意到该函数创建了不同的键,即使我用相同的KeyAgreement两次调用它!如果有人建议我会很高兴!
谢谢你的时间!
我想使用 itextpdf.5.4.1 下载 pdf 文件并将其转换为纯文本。对于其中的大多数,我的代码有效,但对于其中之一,当我尝试读取文件时遇到以下错误。
PdfReader reader = new PdfReader(pdf_file_path);
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Primitive
Run Code Online (Sandbox Code Playgroud)
是不是说这个pdf是受保护的,没有办法提取文本?
我正在开发一个 C# 应用程序,它使用由 Bouncy Castle (BC) 库实现的 PGP 加密/解密消息。我知道 PKI,但 PGP 中的密钥让我有点失望。我查看了 BC 示例/源代码和 PGP RFC,但提出了更多问题。
是 Secretkey == Session 密钥吗?
Secretkey == 对称密钥吗?
Secretkey == 私钥(pub/priv 密钥对)吗?至少以下内容似乎表明密钥是私钥。
internal static PgpPrivateKey FindSecretKey(PgpSecretKeyRingBundle pgpSec, long keyID, char[] pass)
Run Code Online (Sandbox Code Playgroud)
RFC 说密钥包含有关公钥的信息,或者可能是公钥本身(至少这是我的阅读)。
另外,我在某处读到的 Secretkey 基本上是一个密码加密的私钥。
何时/为什么我需要 PGP 协议中的密钥?签名还是加密?
谢谢
我正在尝试对 AES-GCM 进行一些研究。我正在尝试使用 Bouncy Castle 的 AES-GCM 算法实现加密一些数据,然后使用 openSSL 的 AES-GCM 对其进行解密,但我不能。
我检查了 Bouncy Castle,它返回一个输出(密文的长度等于输入的长度加上认证标签的长度),但在 openSSL 中有 2 个输出...... 1 是等于输入长度的密文,另一个输出是标签长度。
我检查了两者都遵循相同的标准 NIST 800-38D。我检查了几个帖子,但没有提到如何去做。但也没有提到我们不能。任何的想法?
我正在使用 secp256r1 曲线和使用 BouncyCastle 的 SHA256 算法实现 ECDSA 签名生成。
对于某些输入,签名长度为 127 个字符。我觉得开头的“0”被删除了,因为签名被存储到 ECDSASigner 类中的 BigInteger 数据类型。
我已经使用确定性方法添加了来自 rfc6979 ECDSA 签名的样本
代码的相关部分:-
//Private key used in hex format -C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721
String secretNumberK = "09F634B188CEFD98E7EC88B1AA9852D734D0BC272F7D2A47DECC6EBEB375AAD4";
SecureRandom secureRandom = new FixedSecureRandom(Hex.decode(secretNumber));
ECPrivateKeyParameters ecPrivateKeySpec = Util.getECPriKeyParameter(ecPrivateKey);//it is the PrivateKey of the sample shown
byte[] messageInHex = Hex.decode("test");
ECDSASigner ecdsaSigner = new ECDSASigner();
ecdsaSigner.init(true, new ParametersWithRandom(ecPrivateKeySpec,
secureRandom));
BigInteger[] sig = ecdsaSigner.generateSignature(Util
.generateSHAHash(messageInHex));
flag = true;
LOG.debug("r:: " + sig[0].toString(16).toString());
LOG.debug("s:: " + sig[1].toString(16).toString()); …Run Code Online (Sandbox Code Playgroud) 我编写了以下代码,以使用证书库中的证书验证文件的签名.但是,当我尝试获取其签名并将其传递给SignedData方法时,我得到以下异常.
org.bouncycastle.cms.CMSException: Malformed content.
at org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
at org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
at org.bouncycastle.cms.CMSSignedData.<init>(Unknown Source)
at VerifyFinal.main(VerifyFinal.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.IllegalArgumentException: unknown object in getInstance: org.bouncycastle.asn1.DERApplicationSpecific
at org.bouncycastle.asn1.ASN1Sequence.getInstance(Unknown Source)
at org.bouncycastle.asn1.cms.ContentInfo.getInstance(Unknown Source)
... 9 more
Run Code Online (Sandbox Code Playgroud)
下面是我用来验证文件签名的代码.
Security.addProvider(new BouncyCastleProvider());
KeyStore msCertStore = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
msCertStore.load(null, null);
X509Certificate cer = ((X509Certificate) msCertStore.getCertificate("Software View Certificate Authority"));
PublicKey pubKey = cer.getPublicKey();
byte[] sigToVerify = cer.getSignature();
Signature signature = Signature.getInstance("SHA1WithRSA", "BC");
signature.initVerify(pubKey);
CMSSignedData cms = new CMSSignedData(cer.getSignature()); …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
SSLContext sslContext = SSLContext.getInstance("TLS", BouncyCastleProvider.PROVIDER_NAME);
sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
SSLEngine sslEngine = sslContext.createSSLEngine();
String[] suites = { "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" };
sslEngine.setEnabledCipherSuites(suites);
Run Code Online (Sandbox Code Playgroud)
谢谢。
编辑:我发现我应该使用BouncyCastleJsseProviderwhich 需要一个SecureRandom对象,如下所示:
sslContext.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());
Run Code Online (Sandbox Code Playgroud)
使用新的提供程序后,我在我的代码库中得到以下堆栈跟踪,据我所知,它应该像以前一样工作:
Aug 17, 2017 8:47:32 PM org.bouncycastle.jsse.provider.ProvTlsServer notifyAlertRaised
INFO: Server raised fatal(2) handshake_failure(40) alert: Failed to read record
org.bouncycastle.tls.TlsFatalAlert: handshake_failure(40)
at org.bouncycastle.tls.AbstractTlsServer.getSelectedCipherSuite(Unknown Source)
at org.bouncycastle.jsse.provider.ProvTlsServer.getSelectedCipherSuite(Unknown Source)
at org.bouncycastle.tls.TlsServerProtocol.sendServerHelloMessage(Unknown Source)
at org.bouncycastle.tls.TlsServerProtocol.handleHandshakeMessage(Unknown Source)
at org.bouncycastle.tls.TlsProtocol.processHandshakeQueue(Unknown Source)
at org.bouncycastle.tls.TlsProtocol.processRecord(Unknown Source)
at org.bouncycastle.tls.RecordStream.readRecord(Unknown Source)
at org.bouncycastle.tls.TlsProtocol.safeReadRecord(Unknown Source)
at org.bouncycastle.tls.TlsProtocol.offerInput(Unknown Source)
at …Run Code Online (Sandbox Code Playgroud) 尝试使用以下内容读取 PEM 格式的 PKCS8 私钥:
private static PrivateKey loadPrivateKey()
throws IOException, GeneralSecurityException, OperatorCreationException, PKCSException {
FileReader fileReader = new FileReader(certsRoot + "/pep-client-key.pem");
PEMParser keyReader = new PEMParser(fileReader);
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
InputDecryptorProvider decryptionProv = new JceOpenSSLPKCS8DecryptorProviderBuilder().build("mypassword".toCharArray());
Object keyPair = keyReader.readObject();
PrivateKeyInfo keyInfo;
if (keyPair instanceof PKCS8EncryptedPrivateKeyInfo) {
keyInfo = ((PKCS8EncryptedPrivateKeyInfo) keyPair).decryptPrivateKeyInfo(decryptionProv); // Exception thrown from here
keyReader.close();
return converter.getPrivateKey(keyInfo);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
生成此错误:
org.bouncycastle.pkcs.PKCSException: unable to read encrypted data: 1.2.840.113549.1.5.13 not available: Cannot find any provider supporting 1.2.840.113549.3.7 …Run Code Online (Sandbox Code Playgroud) 我正在测试 BouncyCastle 以使用ECDSA,验证签名nist P251。(Xamarin 的加密 API 尚未实现,我开始使用 Bouncy Castle 库。)
无论如何,我在下面的代码中面临的是......方法 B 与C#API一起正常工作,方法 A 不是。A 方法的 ECPoint 看起来有问题,但我无法检查详细信息。
(我已经检查过,但无法修复。)
我应该如何更改A方法?欢迎任何想法。提前致谢。
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Nist;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Math.EC;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities.Encoders;
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace TestMe
{
class Program
{
public static byte[] HexStringToByteArray(string Hex)
{
byte[] Bytes = new byte[Hex.Length / 2];
int[] HexValue = new int[] { 0x00, 0x01, 0x02, …Run Code Online (Sandbox Code Playgroud) bouncycastle ×10
java ×7
cryptography ×3
ecdsa ×2
encryption ×2
aes ×1
android ×1
c# ×1
certificate ×1
itext ×1
openssl ×1
pdf ×1
pgp ×1
secret-key ×1
security ×1
sign ×1
signature ×1
ssl ×1
sslengine ×1