标签: encryption

如何根据公共和私人指数计算RSA模数?

我有一个带模数m,公共指数e和私有指数的RSA私钥d,但我使用的程序需要模数的素因子p和q.

有可能使用e和d得到p和q?

encryption rsa

11
推荐指数
3
解决办法
2万
查看次数

使用带有外部 Azure KeyVault (HSM) 密钥的 BouncyCastle 创建证书时签名无效

我正在尝试生成由存储在 Azure KeyVault 中的密钥对自签名的证书。

我的最终结果是带有无效签名的证书:

在此处输入图片说明

生成证书参数:

     DateTime startDate = DateTime.Now.AddDays(-30);
     DateTime expiryDate = startDate.AddYears(100);

     BigInteger serialNumber = new BigInteger(32, new Random());
     X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();

     X509Name selfSignedCA = new X509Name("CN=Test Root CA");

     certGen.SetSerialNumber(serialNumber);
     certGen.SetIssuerDN(selfSignedCA); //Self Signed
     certGen.SetNotBefore(startDate);
     certGen.SetNotAfter(expiryDate);
     certGen.SetSubjectDN(selfSignedCA);
      
Run Code Online (Sandbox Code Playgroud)

获取对 Azure KeyVault 存储密钥的引用(类似 HSM 的服务):

    //Create a client connector to Azure KeyVault
    var keyClient = new Azure.Security.KeyVault.Keys.KeyClient(
         vaultUri: new Uri("https://xxxx.vault.azure.net/"),
         credential: new ClientSecretCredential(
             tenantId: "xxxx", //Active Directory
             clientId: "xxxx", //Application id?
             clientSecret: "xxxx"
             )
         );

        var x …
Run Code Online (Sandbox Code Playgroud)

c# encryption bouncycastle .net-core azure-keyvault

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

使用 x5c 和 x5t 参数创建 JWK 密钥

我需要生成具有以下参数的 JWK:

\n
    \n
  • \xe2\x80\x9ckty\xe2\x80\x9d:密钥类型

    \n
  • \n
  • \xe2\x80\x9ckid\xe2\x80\x9d:密钥 ID

    \n
  • \n
  • \xe2\x80\x9cuse\xe2\x80\x9d:\xe2\x80\x9csig\xe2\x80\x9d 公钥使用

    \n
  • \n
  • \xe2\x80\x9cn\xe2\x80\x9d:模数

    \n
  • \n
  • \xe2\x80\x9ce\xe2\x80\x9d: \xe2\x80\x9cAQAB\xe2\x80\x9d 公共指数

    \n
  • \n
  • \xe2\x80\x9cx5c\xe2\x80\x9d:X.509 证书链

    \n
  • \n
  • \xe2\x80\x9cx5t\xe2\x80\x9d:X.509 证书 SHA-1 指纹

    \n
  • \n
\n

笔记:

\n
    \n
  • JWK 应包含使用 RSA 算法的公钥。RSA 提供用于密钥匹配目的的密钥 ID。

    \n
  • \n
  • 应包含使用 \xe2\x80\x9cx5t\xe2\x80\x9d (X.509 SHA-1 指纹)和 \xe2\x80\x9cx5c\xe2\x80\x9d (X.509\n证书链)的 X.509 证书参数

    \n
  • \n
\n

前 5 个参数(“kty”、“kid”、“use”、“n”、“e”)相当简单,不是问题。但是,对于“x5c”和“x5t”组件,我不确定如何生成它们。看来我可以使用https://www.samltool.com/self_signed_certs.php上找到的工具创建 x509 证书,我想生成的 x509 证书将包含 x5c 参数。这是正确的吗?我如何从中生成 x5t(证书指纹)?

\n

感谢所有帮助。

\n

encryption x509certificate x509 jwt jwk

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

如何加密字符串并获得等长的加密字符串?

我的问题如下:

在现有数据库中,我想要在几列中加密数据.列包含不同长度的字符串.

我不想更改列的大小,因此加密需要生成输入文本的等长文本表示.

加密算法的强度是次要的,但我当然希望它能够尽可能强大.否则我不需要加密数据.但最重要的是输出的大小.

这可能吗?如果是这样,我该怎么做?

我有兴趣在.NET中这样做.没有数据库级加密.

.net encryption

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

Node.js和加密库

我在使用Node的加密库时遇到了奇怪的问题.我写了这个简单的AES测试脚本:

var cipher = crypto.createCipher('aes-256-cbc','InmbuvP6Z8')
var text = "123|123123123123123";
cipher.update(text,'utf8','hex')
var crypted = cipher.final('hex')
var decipher = crypto.createDecipher('aes-256-cbc','InmbuvP6Z8')
decipher.update(crypted,'hex','utf8')
var dec = decipher.final('utf8')
Run Code Online (Sandbox Code Playgroud)

当我执行console.log(dec)时,它为null.出于某种原因,如果我将测试设置为"123 | 123123",它可以工作.那么为什么"123 | 123123"工作但"123 | 123123123123123"不工作?

encryption aes node.js node-crypto

10
推荐指数
2
解决办法
2万
查看次数

如何将String转换为SecretKey

我想将String转换为secretKey

public void generateCode(String keyStr){ 
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128); // 192 and 256 bits may not be available
// Generate the secret key specs.
secretKey skey=keyStr;  //How can I make the casting here
//SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用BASE64Decoder而不是secretKey,但我面临的一个问题是我无法指定密钥长度.

编辑: 我想从另一个地方调用此功能

 static public String encrypt(String message , String key , int keyLength) throws Exception {
     // Get the KeyGenerator
   KeyGenerator kgen = KeyGenerator.getInstance("AES");
    kgen.init(keyLength); // 192 and 256 bits may not be available
    // Generate …
Run Code Online (Sandbox Code Playgroud)

java encryption

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

使用Dropbox API进行应用程序导出合规性

之前已经问过这个问题(或者这个问题的变体),但是由于Apple的出口合规规则相对频繁地变化,似乎没有人得到一个直接的答案,我想我会问.

我编写了一个使用Dropbox API 0.2版的iPhone应用程序.

我已经通过电子邮件向Apple发送了关于此特定API的使用情况,我将确保更新这个问题,因为我了解更多并听取了Apple的回复.与此同时,如果任何开发人员在他们的iPhone应用程序中使用Dropbox API,您是否将应用程序标记为使用加密?

编辑:仔细检查后,看起来文件数据也使用SSL传输.由于他们的API通过HTTPS使用NSMutableURLRequest类,我仍然无法确定此API是否"使用加密".如果在App Store提交页面中我标记它确实包含加密,那么Apple会询问我是否使用了大于64位对称加密密钥.

encryption cocoa-touch objective-c dropbox app-store

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

在C#中保护加密密钥

我知道.NET框架中提供的许多加密提供程序以及如何使用它们的基础知识.这很简单.

但我担心的是这个.

假设我想使用这些库来加密XML序列化对象,以防止篡改以及任何人出现并查看这些文件内容的能力.

我一直留下的问题是解密这些数据的密钥需要在我的应用程序中的某个地方存储为常量.基本上使整个练习变得毫无意义.

那么,如何在可拆卸的应用程序中安全地存储加密算法的密钥?

编辑:所以如果我正确理解下面的两个答案.这意味着基本上任何实现(为了安全)都要求它只读或写,但绝不是两者兼而有之?它是否正确?

c# vb.net encryption cryptography

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

这个Java加密代码线程安全吗?

我想将以下代码用于高并发性应用程序,其中某些数据必须加密和解密.所以我需要知道应该同步这段代码的哪一部分,如果有的话,以避免不可预测的问题.

public class DesEncrypter {
    Cipher ecipher;
    Cipher dcipher;

    // 8-byte Salt
    byte[] salt = {
        (byte)0xA9, (byte)0x9B, (byte)0xC8, (byte)0x32,
        (byte)0x56, (byte)0x35, (byte)0xE3, (byte)0x03
    };

    int iterationCount = 19;

    DesEncrypter(String passPhrase) {
        try {
            // Create the key
            KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt, iterationCount);

            SecretKey key = SecretKeyFactory.getInstance( "PBEWithMD5AndDES").generateSecret(keySpec);
            ecipher = Cipher.getInstance(key.getAlgorithm());
            dcipher = Cipher.getInstance(key.getAlgorithm());

            // Prepare the parameter to the ciphers
            AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);

            // Create the ciphers
            ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
            dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
        } …
Run Code Online (Sandbox Code Playgroud)

java encryption cryptography thread-safety

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

Java RSA加密

我试图来回编码一个简单的字符串"测试".

public static String encode(Key publicKey, String data) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {

    byte[] byteData = data.getBytes(); // convert string to byte array

    Cipher cipher = Cipher.getInstance(ALGORITHM); // create conversion processing object
    cipher.init(Cipher.ENCRYPT_MODE, publicKey); // initialize object's mode and key

    byte[] encryptedByteData = cipher.doFinal(byteData); // use object for encryption

    return new String(encryptedByteData); // convert encrypted byte array to string and return it

}

public static String decode(Key privateKey, String data) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {

    byte[] …
Run Code Online (Sandbox Code Playgroud)

java encryption rsa long-integer

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