在JavaScript中考虑以下字符串:
"TEST NAME\TEST ADDRESS"
Run Code Online (Sandbox Code Playgroud)
(它只包含一个"\",无法更改).
现在,上面的字符串需要通过"\"char分成两个字符串.
结果字符串:
"TEST NAME"
"TEST ADDRESS"
Run Code Online (Sandbox Code Playgroud)
如何,这可以在JavaScript中完成?
从HSM检索私钥时解密数据时收到错误.
我在java.security中添加了sunpkcs11提供程序.因此,不要通过代码添加提供程序.文本已成功加密.但是,在解密加密文本时,我在下面的行中出现以下错误:
cipher.init(Cipher.DECRYPT_MODE, privateKey);
Run Code Online (Sandbox Code Playgroud)
我在这里失踪的是什么?
错误:
Caused by: java.security.InvalidKeyException: Private key must be instance of RSAPrivate(Crt)Key or have PKCS#8 encoding
at sun.security.pkcs11.P11RSAKeyFactory.implTranslatePrivateKey(P11RSAKeyFactory.java:101) [sunpkcs11.jar:1.7.0_85]
at sun.security.pkcs11.P11KeyFactory.engineTranslateKey(P11KeyFactory.java:132) [sunpkcs11.jar:1.7.0_85]
at sun.security.pkcs11.P11KeyFactory.convertKey(P11KeyFactory.java:65) [sunpkcs11.jar:1.7.0_85]
at sun.security.pkcs11.P11RSACipher.implInit(P11RSACipher.java:199) [sunpkcs11.jar:1.7.0_85]
at sun.security.pkcs11.P11RSACipher.engineInit(P11RSACipher.java:168) [sunpkcs11.jar:1.7.0_85]
at javax.crypto.Cipher.init(Cipher.java:1068) [jce.jar:1.7.0_85]
at javax.crypto.Cipher.init(Cipher.java:1012) [jce.jar:1.7.0_85]enter code here
Run Code Online (Sandbox Code Playgroud)
以下是代码:
import java.io.ByteArrayOutputStream;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.Certificate;
import javax.crypto.Cipher;
import javax.xml.bind.DatatypeConverter;
import sun.security.pkcs11.SunPKCS11;
public class App {
public static void main(String[] args) throws Exception {
try {
String passphrase = "mysecretkey";
SunPKCS11 provider …Run Code Online (Sandbox Code Playgroud) 在Java中,我想编写一个正则表达式来执行以下操作:
源字符串:abcdefg
输出字符串:ab***fg
源字符串:123456789
输出字符串:12*****89
源字符串:a123d
输出字符串:a1*3d