第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用 IAIK JCE 在 Java 中使用 PKCS#5 格式的 PBE 加密 RSA 私鑰?

如何使用 IAIK JCE 在 Java 中使用 PKCS#5 格式的 PBE 加密 RSA 私鑰?

阿晨1998 2021-10-27 10:43:06
我創(chuàng)建了一個(gè) RSA 密鑰對(duì)?,F(xiàn)在,我正在嘗試使用 DES 算法加密私鑰,將其格式化為 PKCS#5 并將其打印在控制臺(tái)上。不幸的是,生成的私鑰不起作用。當(dāng)我嘗試使用它時(shí),輸入正確的密碼后,ssh 客戶端返回密碼無(wú)效:加載密鑰“test.key”:用于解密私鑰的密碼不正確可以請(qǐng)有人告訴我我錯(cuò)在哪里嗎?這是代碼:private byte[] iv;public void generate() throws Exception {    RSAKeyPairGenerator generator = new RSAKeyPairGenerator();    generator.initialize(2048);    KeyPair keyPair = generator.generateKeyPair();    String passphrase = "passphrase";    byte[] encryptedData = encrypt(keyPair.getPrivate().getEncoded(), passphrase);    System.out.println(getPrivateKeyPem(Base64.encodeBase64String(encryptedData)));}private byte[] encrypt(byte[] data, String passphrase) throws Exception {    String algorithm = "PBEWithMD5AndDES";    salt = new byte[8];    int iterations = 1024;    // Create a key from the supplied passphrase.    KeySpec ks = new PBEKeySpec(passphrase.toCharArray());    SecretKeyFactory skf = SecretKeyFactory.getInstance(algorithm);    SecretKey key = skf.generateSecret(ks);    // Create the salt from eight bytes of the digest of P || M.    MessageDigest md = MessageDigest.getInstance("MD5");    md.update(passphrase.getBytes());    md.update(data);    byte[] digest = md.digest();    System.arraycopy(digest, 0, salt, 0, 8);    AlgorithmParameterSpec aps = new PBEParameterSpec(salt, iterations);    Cipher cipher = Cipher.getInstance(AlgorithmID.pbeWithSHAAnd3_KeyTripleDES_CBC.getJcaStandardName());    cipher.init(Cipher.ENCRYPT_MODE, key, aps);    iv = cipher.getIV();    byte[] output = cipher.doFinal(data);    ByteArrayOutputStream out = new ByteArrayOutputStream();    out.write(salt);    out.write(output);    out.close();    return out.toByteArray();}
查看完整描述

2 回答

?
森欄

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊

先生

我認(rèn)為在調(diào)用 encrypt 之前,出于安全原因,您需要再解密兩次。也可以用胡椒鹽和胡椒代替鹽。不要將算法與 aes256 混合。


查看完整回答
反對(duì) 回復(fù) 2021-10-27
  • 2 回答
  • 0 關(guān)注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)