我试图了解Java java.security.Signature类的功能.如果我计算SHA1消息摘要,然后使用RSA加密该摘要,我得到一个不同的结果,要求Signature类签署相同的东西:
// Generate new key
KeyPair keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
String plaintext = "This is the message being signed";
// Compute signature
Signature instance = Signature.getInstance("SHA1withRSA");
instance.initSign(privateKey);
instance.update((plaintext).getBytes());
byte[] signature = instance.sign();
// Compute digest
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
byte[] digest = sha1.digest((plaintext).getBytes());
// Encrypt digest
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, privateKey);
byte[] cipherText = cipher.doFinal(digest);
// Display results
System.out.println("Input data: " + plaintext);
System.out.println("Digest: " + bytes2String(digest));
System.out.println("Cipher text: " + bytes2String(cipherText)); …Run Code Online (Sandbox Code Playgroud) 我来自RPC世界,但目前正在调查使用REST是否对我的项目来说是一个好主意.至于我从维基百科中了解到,RESTful服务的基本思想是提供对集合及其各个元素的访问.
在我的情况下,服务器将是一个测量仪器.我必须能够启动,停止和暂停测量程序,并随时读取数据.
目前,我正在考虑以下内容:
但是,我不确定这是否适合REST模型,因为我在这里并不真正使用集合或元素.
我的问题:我如何访问单例资源并对服务器执行启动/停止请求会破坏RESTful无状态约束?