标签: public-key-encryption

从 DER 解码字符串创建 X509Certicate

我有一个 X509Certificate,我将它写入/打印到一个文件中,如下所示。(我不是在写编码字节,因为我想阅读证书的内容)

X509Certificate cer = generateCertificate(); // cer is DER encoded
writeToFile( cer.toString() ); // cer.toString() converts DER to UTF/ASCII???
Run Code Online (Sandbox Code Playgroud)

后来我想将此文件(以上)作为字符串读取并创建一个新的 X509Certificate。

String cerStr = readCerFromFile(); // Read what is written above. In ASCII/ UTF format
ByteArrayInputStream bais = null;
try {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    bais = new ByteArrayInputStream(cerStr.getBytes());
    return (X509Certificate) cf.generateCertificate(bais);
} ...
Run Code Online (Sandbox Code Playgroud)

这将引发以下异常。

Java.security.cert.CertificateParsingException: Invalid DER-encoded certificate data
Run Code Online (Sandbox Code Playgroud)

很明显,我没有将 cerStr 转换为 DER 格式(我不知道是否可以转换为 DER )。任何人都可以解释如何从未编码的字符串创建 X509Certicate 。

提前致谢。!

cryptography public-key-encryption x509

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

如何在c#中填写RSAParameters值

我在我的项目中使用下面的代码进行加密,一切正常.

RSACryptoServiceProvider x_alg = new RSACryptoServiceProvider(  );

// export only the public key 
RSAParameters x_public_params = x_alg.ExportParameters(false);

// export the private key 
RSAParameters x_private_params = x_alg.ExportParameters(true);
Run Code Online (Sandbox Code Playgroud)

现在客户端更改了要求,并且他希望将所有RSAParameters值存储到配置文件中,并提供以下详细信息用于演示

<project name="netCard Server1">
  <key length="256"></key>
  <D length="64">00000000000000000000000000000000000000000000000000000000000019C5</D>
  <DP length="32">00000000000000000000000000000061</DP>
  <DQ length="32">00000000000000000000000000000065</DQ>
  <Exponent length="6">000DCD</Exponent>
  <InverseQ length="32">0000000000000000000000000000003B</InverseQ>
  <Modulus length="64">0000000000000000000000000000000000000000000000000000000000002C95</Modulus>
  <P length="32">00000000000000000000000000000065</P>
  <Q length="32">00000000000000000000000000000071</Q>
  <text length ="64">0123456789ABCDEF111111111111111125FE2222222222222233333333334444</text>
  <cipher length ="64">0000000000000000000000000000000000000000000000000000000000000000</cipher>
</project>
Run Code Online (Sandbox Code Playgroud)

现在,问题是当我导入RSAParameters值时,我收到了错误的数据异常

c# rsa public-key-encryption

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

非对称加密:更改我的私钥

显然我对异步加密还不够了解。

因此,在任何非对称加密系统中,我都可以请求一个密钥,它会为我生成一个我应该保密的私钥和一个我应该广泛公开的公钥。

但当然,无论我如何存储它,我永远无法绝对确定我的私钥没有被泄露。所以,就像密码一样,我想经常更改我的私钥。

我的问题是,在任何非对称加密系统中:每当我创建一个新的私钥时,我也会得到一个新的公钥,对吗?那么我的旧公钥不能与我的新私钥一起使用吗?...这意味着任何想要使用我的加密与我通信的人都必须首先获得我的新公钥,对吧?

或者有什么方法可以经常更改我的私钥,而不需要我的朋友不断更新我的公钥?

encryption public-key-encryption

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

如何使用apache vfs2 for sftp with public-private-key and without password

目前我正在使用apache vfs2从sftp下载文件.对于身份验证,我使用用户名和密码.

有没有办法只使用vfs2与public-private-keys和没有密码?

我想我已经使用了这个功能,但是怎么样?将其设置为"是"?

SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(options, "no");
Run Code Online (Sandbox Code Playgroud)

这是我目前的代码(片段):

private boolean downloadFile(){

    StandardFileSystemManager sysManager = new StandardFileSystemManager();

    //download der Datei
    try {
        sysManager.init();

        FileObject localFile = sysManager.resolveFile(localFilePath);

        FileObject remoteFile = sysManager.resolveFile(createConnectionString(host, user, password, fileName, port),createDefaultOptions());

        //Selectors.SELECT_FILES --> A FileSelector that selects only the base file/folder.
        localFile.copyFrom(remoteFile, Selectors.SELECT_FILES);


    } catch (Exception e) {
        logger.error("Downloading file failed: " + e.toString());
        return false;
    }finally{
        sysManager.close();
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

private FileSystemOptions createDefaultOptions() throws FileSystemException{

    //create options for sftp
    FileSystemOptions options = new FileSystemOptions();
    //ssh …
Run Code Online (Sandbox Code Playgroud)

java sftp public-key-encryption apache-commons-vfs

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

如何在 Kleopatra 中为 OpenPGP 证书提供最高信任级别?

我想给予证书最高的信任级别。我需要这样做,因为该证书是我的,但在格式化我的电脑之前我没有导出它。

我已经从公钥服务器下载了它,并且我的私钥保存在 KeePass 中,但我不知道下一步该怎么做。

gnupg openpgp public-key-encryption

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

如何使用 ssh 公钥进行 gpg 加密?

我在一个名为 的文件中有一个公钥key.pub,其内容如下所示:

ssh-rsa AAAAB...<snip>...t+f klahnakoski
Run Code Online (Sandbox Code Playgroud)

我想用它来加密文件gpg。所需的 shell 命令序列是什么?

我想序列看起来像:

  • 将密钥转换为 gpg 友好格式
  • 发明一些凭据来签署密钥
  • 发明一个用户以方便将密钥添加到密钥环
  • 执行加密

谢谢!

ssh gnupg public-key-encryption

6
推荐指数
2
解决办法
2319
查看次数

gpg:对不起,没有终端请求 - 无法获得输入

解密时我收到以下错误:

$ eyaml decrypt -s 'ENC and the key goes on here'
Run Code Online (Sandbox Code Playgroud)
.gnupg --quiet --no-secmem-warning --no-permission-warning --no-tty --yes --decrypt)
failed with: gpg: Sorry, no terminal at all requested - can't get input

我检查了我的钥匙,一切都井然有序.在这一点上,我没有选择.

architecture linux gnupg snakeyaml public-key-encryption

6
推荐指数
3
解决办法
6031
查看次数

为什么在 Diffie-Hellman 密钥交换中使用素数?

Diffie-Hellman 密钥交换算法使用诸如2^8 mod nwheren是素数之类的操作。

使用质数而不是其他数字的原因是什么?

cryptography public-key-encryption diffie-hellman

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

RSACryptoServiceProvider 在 .net 核心中不起作用

我必须调用政府 API,会话密钥需要使用他们提供的公钥进行加密。以下用于加密会话密钥的代码在使用 .NET 框架的 Windows 服务器上运行良好,但我需要使用 .NET 核心在 aws lambda 上托管 API。有以下错误

System.InvalidCastException:无法将“System.Security.Cryptography.RSAOpenSsl”类型的对象转换为“System.Security.Cryptography.RSACryptoServiceProvider”

private static string EncryptRsa(byte[] input)
{
    string output = string.Empty;
    System.Security.Cryptography.X509Certificates.X509Certificate2 cert = new X509Certificate2(@"Cert/server_pub.cer");


    using (RSACryptoServiceProvider csp = (RSACryptoServiceProvider)cert.PublicKey.Key)
    {
        byte[] bytesData = input;
        byte[] bytesEncrypted = csp.Encrypt(bytesData, true);
        output = Convert.ToBase64String(bytesEncrypted);
    }
    return output;
}
Run Code Online (Sandbox Code Playgroud)

我将代码更改为以下,它运行成功,但是当我调用 API 时,它给出一个错误,说会话密钥解密错误,请使用正确的公钥加密会话密钥。

如何获得与RSACryptoServiceProvider.net core类似的加密

private static string EncryptRsa(byte[] input)
{
    string output = string.Empty;
    System.Security.Cryptography.X509Certificates.X509Certificate2 cert = new X509Certificate2(@"Cert/server_pub.cer");


    using (RSA csp = (RSA)cert.PublicKey.Key)
                {
                    byte[] bytesData …
Run Code Online (Sandbox Code Playgroud)

c# public-key-encryption

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

AWS CloudFront 表示公钥无效/超出限制

我正在尝试在 AWS CloudFront 上上传公钥。我生成密钥如下

ssh-keygen -t ecdsa -b 521

我也尝试过

ssh-keygen -b 4096

当我通过控制台上传它时,出现以下错误: com.amazonaws.services.cloudfront.model.InvalidArgumentException:您的请求包含空/无效/超出限制的 RSA 编码密钥(服务:AmazonCloudFront;状态代码:400;错误代码:InvalidArgument;请求 ID:08fa98af-0c02-11ea-b06e-d771d01bbfcb)

结果ssh -V是“OpenSSH_7.7p1,OpenSSL 1.0.2p 14 Aug 2018”。

任何帮助,将不胜感激。谢谢。

public-key-encryption amazon-cloudfront ssh-keygen

6
推荐指数
2
解决办法
5141
查看次数