当前位置: 首页>>代码示例>>Java>>正文


Java SignedObject.getObject方法代码示例

本文整理汇总了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;
}
 
开发者ID:sunenielsen,项目名称:tribaltrouble,代码行数:16,代码来源:Authenticator.java

示例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");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:45,代码来源:Copy.java


注:本文中的java.security.SignedObject.getObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。