gpt4 book ai didi

java - 将字符串转换为字节数组

转载 作者:行者123 更新时间:2023-11-30 06:30:26 26 4
gpt4 key购买 nike

我正在使用 RSA 加密将简单文本转换为加密形式。

我的纯文本是:你好

加密文本:[B@d7eed7

现在,如何将加密文本转换为简单的纯文本我正在使用以下代码

KeyPairGenerator keygenerator = KeyPairGenerator.getInstance("RSA");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keygenerator.initialize(1024, random);

KeyPair keypair = keygenerator.generateKeyPair();
PrivateKey privateKey = keypair.getPrivate();
PublicKey publicKey = keypair.getPublic();
Cipher cipher = Cipher.getInstance("RSA");

String arrayStr = "[b@d7eed7";
byte ciphertext = arrayStr.getBytes();
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] cleartext1 = cipher.doFinal(ciphertext);
System.out.println("the decrypted cleartext is: " + new String(cleartext1));

我得到 javax.crypto.BadPaddingException: Data must start with zero

需要帮助!!

最佳答案

问题是 [B@d7eed7 不是加密文本。它只是显示字节数组的类型和地址,而不是它的内容。

有关详细信息,请参阅 https://stackoverflow.com/a/5500020/367273

关于java - 将字符串转换为字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10431616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com