我有公钥字符串
String publicK = "-----BEGIN PUBLIC KEY-----\n" +
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgFhTDtuYJ5G5LEHMesnf\n" +
"wX9cXZ1b/ozkkpbgtC3ziETiFkOFncbPCskpdbPmXxXv3vrwJ2RQIL2LZLZPe1xT\n" +
"AyQY1DdD8hGqIemMwV2NqfFoEomVL5+QOAKCRiHkGgte6a2+OoTk9JzRP/NVaPkB\n" +
"sdX1/nIPERYen3uDvUSYq83Ite2oDyaZZxj+/r46SadS/g5jWmeqgVoInJw813y7\n" +
"Ee2HgYVbnktlLNhqIGj+1OKmwop+GP7Kk5CAkt9fo4VjRRllDaX1yFCZEbDL254n\n" +
"S+LVOhl4mLBM8764+YVxjyYRC1Nq2rNZfQ602652i+l8u8nGqdiKOKDpjNDvhONP\n" +
"yQIDAQAB\n" +
"-----END PUBLIC KEY-----";
Run Code Online (Sandbox Code Playgroud)
我想转换 PublicKey Object 。
byte[] byteKey = publicK.getBytes();
X509EncodedKeySpec spec = new X509EncodedKeySpec(byteKey);
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePublic(spec);
Run Code Online (Sandbox Code Playgroud)
以上代码抛出异常
java.security.InvalidKeyException: invalid key format
at sun.security.x509.X509Key.decode(X509Key.java:387)
at sun.security.x509.X509Key.decode(X509Key.java:403)
at sun.security.rsa.RSAPublicKeyImpl.<init>(RSAPublicKeyImpl.java:84)
at sun.security.rsa.RSAKeyFactory.generatePublic(RSAKeyFactory.java:298)
at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:201)
Run Code Online (Sandbox Code Playgroud) 我有一个接口和抽象类。
public class TEST extends Abstract implements Inter2{
void print() {
toDO();
}
public static void main(String[] args) {
new TEST().toDO();
}
}
abstract class Abstract {
public void toDO() {
System.out.println("Abstract is called");
}
}
interface Inter2 {
default void toDO() {
System.out.println("Inter2 is called");
}
}
Run Code Online (Sandbox Code Playgroud)
我想强制类接口默认方法而不是抽象类。
我是 C# 新手。我不明白为什么它会产生问题。
CspParameters cspParams = new CspParameters(24);
cspParams.KeyContainerName = "XML_DISG_RSA_KEY";
RSACryptoServiceProvider key = new RSACryptoServiceProvider(cspParams);
Run Code Online (Sandbox Code Playgroud)
下面的代码在我的本地设置中运行良好。但它在客户端不起作用。
他们得到了以下例外。
[CryptographicException:密钥在指定状态下使用无效。]
System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer) +4644432
System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle) +69
System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair() +92
System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize) +173
System.Security.Cryptography.RSACryptoServiceProvider..ctor(CspParameters parameters) +14
Run Code Online (Sandbox Code Playgroud)
请你帮助我好吗。
public interface ABC {
public boolean removeUser(String userId) throws OTPServiceException, RemoteException;
}
ABC abc= mock(ABC.class);
doNothing().when(abc).removeUser(anyString());
Run Code Online (Sandbox Code Playgroud)
我试过这样的.我得到了以下异常.
org.mockito.exceptions.base.MockitoException:
Only void methods can doNothing()!
Example of correct use of doNothing():
doNothing().
doThrow(new RuntimeException())
.when(mock).someVoidMethod();
Above means:
someVoidMethod() does nothing the 1st time but throws an exception the 2nd time is called
Run Code Online (Sandbox Code Playgroud)