我试图使用java匹配多行文本.当我使用Pattern
带Pattern.MULTILINE
修饰符的类时,我能够匹配,但我无法使用(?m).
使用(?m)
和使用相同的模式String.matches
似乎不起作用.
我确信我错过了什么,但不知道是什么.我不太擅长正则表达式.
这是我试过的
String test = "User Comments: This is \t a\ta \n test \n\n message \n";
String pattern1 = "User Comments: (\\W)*(\\S)*";
Pattern p = Pattern.compile(pattern1, Pattern.MULTILINE);
System.out.println(p.matcher(test).find()); //true
String pattern2 = "(?m)User Comments: (\\W)*(\\S)*";
System.out.println(test.matches(pattern2)); //false - why?
Run Code Online (Sandbox Code Playgroud) 我有三个关于SSL的问题我还不完全理解.
如果我正确地得到它,服务器会A
向某个CA提交请求.然后,它使用CA的私钥接收(在验证之后)由公钥+身份+对该信息的描述组成的数字证书.
稍后,客户端B
想要打开SSL通信A
,因此A
发送B
其数字证书.
我的问题是不能B
仅仅拿这个证书,从而窃取身份A
-这将让他们为验证A
到C
,例如.据我所知,C
将使用CA的公钥解密证书,然后它将加密其对称密钥,该密钥只能由真实密钥解密A
.
但是,如果B
能够真正窃取A
身份,我看不到身份验证的发挥作用.除非我遗漏了什么.
第二个问题:如果CA的一部分已经加密,为什么要在证书上使用哈希?这是不是意味着没有人可以乱用数字证书(很有可能)?
如果我是stackoverflow并且我有3台服务器做同样的事情 - 允许客户端访问,读取,识别等 - 我是否必须为3台服务器中的每台服务器提供不同的数字证书.
非常感谢你.
在编写加密实用程序类时,我遇到了以下方法的问题:
public static void destroy(Key key) throws DestroyFailedException {
if(Destroyable.class.isInstance(key)) {
((Destroyable)key).destroy();
}
}
@Test
public void destroySecretKeySpec() {
byte[] rawKey = new byte[32];
new SecureRandom().nextBytes(rawKey);
try {
destroy(new SecretKeySpec(rawKey , "AES"));
} catch(DestroyFailedException e) {
Assert.fail();
}
}
Run Code Online (Sandbox Code Playgroud)
在javax.crypto.spec.SecretKeySpec
上述方法的特定情况下可以正常工作,java7
因为SecretKeySpec(javadocs 7)没有实现Destroyable(javadocs 7)
现在使用java8
类SecretKeySpec(javadocs 8)已经被Destroyable(javadocs 8)和方法Destroyable#destroy现在default
哪个很好,根据这个声明
默认方法使您能够向库的接口添加新功能,并确保与为这些接口的旧版本编写的代码的二进制兼容性.
然后代码编译没有任何问题,尽管类ScretKeySpec
本身没有被更改,单独的接口SecretKey已经.
问题是oracle's jdk8
该destroy
方法有以下实现:
public …
Run Code Online (Sandbox Code Playgroud) 我jaxb
用来从xsd
文件生成java类.它xsd
包含一个元素的定义,其内容是与xsd
枚举相同定义的常量列表.
当使用oracle jdk1.7
(v2.2.4-2
)的JAXB引用实现生成类时,可以迭代枚举列表并为它们分配相同类型的变量.
但是,当使用oracle jdk1.8
(生成1.8.0_45-b15
- 最新发布日期)JAXB引用实现(v2.2.8-b130911.1802
)生成类时,不再可能将列表的元素分配给枚举类型的变量.
任何使用增强型for循环分配或迭代的尝试都以a结束 ClassCastException
java.lang.ClassCastException: java.lang.String cannot be cast to so.jaxb.enums.generated.GConstNameType
at so.jaxb.enums.domain.TestReader.readTest(TestReader.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) …
Run Code Online (Sandbox Code Playgroud) 我有一个叫做Container
:
public class Container {
private final Map<String, Object> map = new HashMap<>();
public void put(String name, Object value) {
map.put(name, value);
}
public Container with(String name, Object value) {
put(name, value);
return this;
}
public Object get(String name) {
return map.get(name);
}
public <R> R get(String name, Function<Object, R> mapper) {
Object value = get(name);
if (null == value) {
return null;
}
return mapper
.apply(value);
}
public <R> R get(String name, Class<R> type) {
Object value …
Run Code Online (Sandbox Code Playgroud) 我正在使用HttpClient处理http请求,当我尝试与目标服务器对接时,出现错误
org.apache.http.conn.ConnectTimeoutException: Connect to prdalonegk.alonegk.com:9090 timed out
Run Code Online (Sandbox Code Playgroud)
prdalonegk.alonegk.com:9090
我的xmpp服务器在哪里
我最近安装了Eclipse Luna来对JSP进行编程.目前我正在尝试将其与JDBC连接.我已经下载了mysql J连接器并添加mysql-connector-java-5.1.31-bin.jar
到构建路径中.我试图在我的浏览器上运行,我收到以下错误:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Run Code Online (Sandbox Code Playgroud)
我很确定我的设置在设置路径方面是正确的.我也在环境变量中设置了CLASSPATH,以防万一是主要问题,但我仍面临同样的问题.
谁能帮我?
我正在尝试使用ListIterator从ArrayList打印,我很确定我做错了因为它不起作用但我不知道如何解决它.所有抓住零件编号的线路都不起作用,不确定原因; P.总是赞赏任何帮助:).
package invoice;
import static java.lang.System.out;
import java.util.*;
public class InvoiceTest {
public static void print(){
}
public static void main (String args[]) {
Scanner imput = new Scanner (System.in);
ArrayList lInvoice = new ArrayList() ;
int counter = 0;
int partCounter;
out.println("Welcome to invoice storer 1.0!");
out.println("To start please enter the number of items: ");
partCounter = imput.nextInt();
while (counter < partCounter){
counter++;
out.println("Please enter the part number:");
Invoice invoice1 = new Invoice(); //Makes invoice 1 use the …
Run Code Online (Sandbox Code Playgroud)