本文整理汇总了Java中java.security.SignedObject.getObject方法的典型用法代码示例。如果您正苦于以下问题:Java SignedObject.getObject方法的具体用法?Java SignedObject.getObject怎么用?Java SignedObject.getObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.SignedObject
的用法示例。
在下文中一共展示了SignedObject.getObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkKey
import java.security.SignedObject; //导入方法依赖的package包/类
private final String checkKey(SignedObject reg_key) {
String reg_code = null;
if (reg_key != null) {
try {
if (RegistrationKey.verify(server.getPublicRegKey(), reg_key)) {
// This cast should not fail, because we signed it and the signature checked out ok
RegistrationInfo reg_info = (RegistrationInfo)reg_key.getObject();
reg_code = RegistrationKey.encode(reg_info.getKey());
}
} catch (Exception e) {
MatchmakingServer.getLogger().warning("Could not verify signature because of: " + e.getMessage());
}
}
return reg_code;
}
示例2: main
import java.security.SignedObject; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
KeyPairGenerator kg = KeyPairGenerator.getInstance(DSA);
kg.initialize(KEY_SIZE);
KeyPair kp = kg.genKeyPair();
Signature signature = Signature.getInstance(DSA);
Test original = new Test();
SignedObject so = new SignedObject(original, kp.getPrivate(),
signature);
System.out.println("Signature algorithm: " + so.getAlgorithm());
signature = Signature.getInstance(DSA, "SUN");
if (!so.verify(kp.getPublic(), signature)) {
throw new RuntimeException("Verification failed");
}
kg = KeyPairGenerator.getInstance(DSA);
kg.initialize(KEY_SIZE);
kp = kg.genKeyPair();
if (so.verify(kp.getPublic(), signature)) {
throw new RuntimeException("Unexpected success");
}
Object copy = so.getObject();
if (!original.equals(copy)) {
throw new RuntimeException("Signed object is not equal "
+ "to original one: " + copy);
}
/*
* The signed object is a copy of an original one.
* Once the copy is made, further manipulation
* of the original object shouldn't has any effect on the copy.
*/
original.set(MAGIC - 1);
copy = so.getObject();
if (original.equals(copy)) {
throw new RuntimeException("Signed object is not a copy "
+ "of original one: " + copy);
}
System.out.println("Test passed");
}