标签: bouncycastle

使用 BouncyCastle Java 实现 CRYSTALS-Kyber

任何人都可以帮助引导我走向正确的方向,甚至只是使用 Kyber 生成密钥对吗?我尝试搜索 BouncyCastle 示例,但找不到任何可以启动的示例。

我正在尝试对一些当前的算法进行基准测试,例如 AES/RSA,这些算法我工作得很好,但即使在 Kyber 上开始使用,我也无法取得任何进展。任何帮助将不胜感激。

我尝试在 Google 上搜索示例,开发人员在其网站上实现了 C# 甚至 Java,但没有 BouncyCastle。他们提到它可以在 BouncyCastle 上使用,但我找不到任何文档,甚至无法帮助实现它。

java cryptography bouncycastle post-quantum-cryptography

1
推荐指数
1
解决办法
1450
查看次数

为什么RC4无法处理大量加密数据?

我有以下代码解密文件.

package encryption;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.Security;

import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

public class Decrypter {

    private static final String PASSWORD = "t_9Y#i@eT[h3}-7!";
    private static final String KEY_ALGORITHM = "PBEWithMD5AndDES";
    private static final String CIPHER_ALGORITHM = "RC4"; //Using Salsa20 or HC256 solves the problem
    private static final String PROVIDER = "BC";

    public static void main(String[] args) throws Exception {
        Security.addProvider(new BouncyCastleProvider());

        File inputFile = new …
Run Code Online (Sandbox Code Playgroud)

java security encryption bouncycastle jce

0
推荐指数
1
解决办法
1951
查看次数

椭圆曲线加密

请给我一个使用Bouncycastle库的示例,该库显示如何在椭圆曲线上添加两个点.

我尝试了以下代码,但我没有得到理论上应该发生的相同结果.

   X9ECParameters x9=NISTNamedCurves.getByName("P-224");
   ECCurve curve=x9.getCurve();
   ECFieldElement x1=new ECFieldElement.Fp(new BigInteger("10"), new BigInteger("8"));
   ECFieldElement y1=new ECFieldElement.Fp(new BigInteger("10"), new BigInteger("9"));
   ECPoint.Fp p1=new ECPoint.Fp(curve, x1, y1);
   ECFieldElement x2=new ECFieldElement.Fp(new BigInteger("10"), new BigInteger("5"));
   ECFieldElement y2=new ECFieldElement.Fp(new BigInteger("10"), new BigInteger("6"));
   ECPoint.Fp p2=new ECPoint.Fp(curve, x2, y2);
   p2=(ECPoint.Fp) p1.add(p2);
   System.out.println(p2.getX().toBigInteger()+" "+p2.getY().toBigInteger());
Run Code Online (Sandbox Code Playgroud)

而且我也没明白什么价值在于提供了第一个BigIntegerECFiledElement.

java bouncycastle elliptic-curve

0
推荐指数
1
解决办法
1881
查看次数

通过充气城堡库将der转换为pem

我发现了许多将pem转换为der的答案。

但是,我找不到将der转换为pem的方法

例如,以下代码生成der编码文件pkcs10.cer

public static void main(String[] args) throws Exception
{
    X509Certificate[] chain = buildChain();
    PEMWriter pemWrt = new PEMWriter(new OutputStreamWriter(System.out));
    pemWrt.writeObject(chain[0]);

    FileWriter fwO = new FileWriter("pkcs10.cer");
    fwO.write((chain[0]).toString());

    fwO.close();
    pemWrt.close();

}
Run Code Online (Sandbox Code Playgroud)

像[0]版本:3序列号:1353995641265 IssuerDN:CN = Test证书开始日期:2012年11月26日星期一21:54:01最终日期:2012年11月26日星期一21:54:51

但是,我不知道如何从der文件中进行pem编码的认证。

java cryptography bouncycastle x509

0
推荐指数
1
解决办法
6050
查看次数

TLS连接:覆盖证书验证

尽管尝试了所有安全措施,我希望我的客户端接受自签名的X.509证书,就像我们服务器中的证书一样.我正在使用WP8 SKD以及用于Windows Phone的Bouncy Castle的C#绑定,名为bouncywp7.1,因此大多数类/方法都可用.

在Android中完成此操作的方法是创建我自己的证书信任管理器,并使其对所有证书都返回true.

public static void allowAllSSL() 
{
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
        @Override
        public boolean verify(final String hostname, final SSLSession session) {
            return true;
        }
    });
    SSLContext context = null;
    try {
        context = SSLContext.getInstance("TLS");
        context.init(null, sTrustManagers, new SecureRandom());
    } catch (final NoSuchAlgorithmException catchException) {
        LoggerFactory.consoleLogger().printStackTrace(catchException);
    } catch (final KeyManagementException catchException) {
        LoggerFactory.consoleLogger().printStackTrace(catchException);
    }
    mFakeFactory = context.getSocketFactory();
    HttpsURLConnection.setDefaultSSLSocketFactory(mFakeFactory);
}
Run Code Online (Sandbox Code Playgroud)

在Windows Phone 8上执行相同操作的最不痛苦的方法是什么?

c# ssl bouncycastle ssl-certificate windows-phone-8

0
推荐指数
1
解决办法
2667
查看次数

使用Bouncy Castle(C#)生成PGP密钥环会导致密钥ID为FFFFFFFF

我尝试使用Bouncy Castle for C#生成一个RSA密钥对.我按照http://bouncycastle-pgp-cookbook.blogspot.de/2013_01_01_archive.html上的 Java教程进行操作,并创建主密钥和签名密钥.我的代码看起来像

IAsymmetricCipherKeyPairGenerator generator
    = GeneratorUtilities.GetKeyPairGenerator("RSA");
generator.Init(keyRingParams.RsaParams);

/* Create the master (signing-only) key. */
PgpKeyPair masterKeyPair = new PgpKeyPair(
    PublicKeyAlgorithmTag.RsaSign,
    generator.GenerateKeyPair(),
    DateTime.UtcNow);
Debug.WriteLine("Generated master key with ID "
    + masterKeyPair.KeyId.ToString("X"));

PgpSignatureSubpacketGenerator masterSubpckGen
    = new PgpSignatureSubpacketGenerator();
masterSubpckGen.SetKeyFlags(false, PgpKeyFlags.CanSign
    | PgpKeyFlags.CanCertify);
masterSubpckGen.SetPreferredSymmetricAlgorithms(false,
    (from a in keyRingParams.SymmetricAlgorithms
        where a.IsSelected
        select (int) a.Value).ToArray());
masterSubpckGen.SetPreferredHashAlgorithms(false,
    (from a in keyRingParams.HashAlgorithms
        where a.IsSelected
        select (int) a.Value).ToArray());

/* Create a signing and encryption key for daily use. */
PgpKeyPair encKeyPair = new PgpKeyPair(
    PublicKeyAlgorithmTag.RsaGeneral, …
Run Code Online (Sandbox Code Playgroud)

c# bouncycastle openpgp

0
推荐指数
1
解决办法
9678
查看次数

如何在netbeans java中使用充气城堡(DES)加密和解密文件?

如何使用充气城堡(DESEngine)加密和解密文件(而不是字符串)?我之前搜索过但找不到帮助.

encryption 3des cryptography des bouncycastle

0
推荐指数
1
解决办法
1万
查看次数

使用AES解密文件时,密码doFinal pad块损坏

我正在创建一个程序,允许用户上传和下载加密文件,如果他们具有正确的权限,则解密它们.加密和上传很好,下载也是如此,但是当我尝试解密时,我得到"pad block corrupted"错误.

我想要做的是获取加密文件,然后制作一个未加密的副本

我缩短了我的意思所以请不要评论它看起来不完整.

注册机:

public static SecretKey genGroupSecretKey() {
    try {
        KeyGenerator keyGen = KeyGenerator.getInstance("AES", "BC");
        keyGen.init(128);
        return keyGen.generateKey();
    } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
        System.err.println("Error: " + e.getMessage());
        e.printStackTrace(System.err);
    }
    return null;
}
Run Code Online (Sandbox Code Playgroud)

加密:

try (FileInputStream fis = new FileInputStream(sourceFile)) {
    response = Utils.decryptEnv((byte[]) tempResponse.getObjContents().get(0), fsSecretKey, ivSpec);

    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
    cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec);

    do {
        byte[] buf = new byte[4096];

        int n = fis.read(buf); // can throw an IOException
        else if (n < 0) …
Run Code Online (Sandbox Code Playgroud)

java encryption bouncycastle aes

0
推荐指数
1
解决办法
1万
查看次数

如何使用存储在智能卡中的密钥生成CSR

我目前正试图通过使用存储私钥和公​​钥的bouncycastle lib(java或C#)和智能卡(epass2003)来生成CSR.

我发现这个例子.Net以编程的方式签署了Bouncy Castle的PKCS#10请求,但是有必要直接访问这对密钥,这是不可能的,因为智能卡不允许访问他们的私钥.

任何人都可以通过使用智能卡中的一对密钥来帮助生成CSR吗?

最好的祝福

c# bouncycastle csr smartcard x509certificate

0
推荐指数
1
解决办法
1774
查看次数

SHA256withECDSA签名算法的输出格式是什么?

我正在使用secp256k1曲线生成密钥对。然后,我使用私钥对随机字符串进行签名:

byte[] content = "random string".getBytes();
Signature dsa = Signature.getInstance("SHA256withECDSA");
dsa.initSign(privateKey);
dsa.update(content);
byte[] signature = dsa.sign();
Run Code Online (Sandbox Code Playgroud)

签名字节数组具有以下内容:

[48, 68, 2, 32, 11, 25, 119, -64, -107, 53, -84, 65, -18, -81, -56, 34,
11, 29, 120, 38, -102, 105, -89, -9, -46, -28, 91, 59, -74, -103, -53,
117, 81, -37, 85, 27, 2, 32, 55, 97, -11, -85, 110, -106, 81, -94, 7,
112, 125, -29, -16, -8, 121, 123, 14, -17, -7, -10, 1, -80, -117, 86,
98, …
Run Code Online (Sandbox Code Playgroud)

java cryptography bouncycastle ecdsa

0
推荐指数
1
解决办法
2238
查看次数