• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java KeyPairGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.i2p.crypto.eddsa.KeyPairGenerator的典型用法代码示例。如果您正苦于以下问题:Java KeyPairGenerator类的具体用法?Java KeyPairGenerator怎么用?Java KeyPairGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



KeyPairGenerator类属于net.i2p.crypto.eddsa包,在下文中一共展示了KeyPairGenerator类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: Ed25519Provider

import net.i2p.crypto.eddsa.KeyPairGenerator; //导入依赖的package包/类
/**
 * Constructs a new instance of the Ed25519Provider.
 */
public Ed25519Provider() {
	super(NAME, 1.0, "Provider wrapping eddsa classes");

	put("KeyPairGenerator.Ed25519", KeyPairGenerator.class.getName());
	put("KeyFactory.Ed25519", KeyFactory.class.getName());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:Ed25519Provider.java


示例2: KeyManager

import net.i2p.crypto.eddsa.KeyPairGenerator; //导入依赖的package包/类
public KeyManager(_KeyStore store) {
    keySpecs = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512);
    keys = new ArrayList<>();

    String seedBase64 = store.load().orElseGet(() -> {
        KeyPair pair = (new KeyPairGenerator()).generateKeyPair();
        String keyEncoded = MxBase64.encode(pair.getPrivate().getEncoded());
        store.store(keyEncoded);
        return keyEncoded;
    });
    byte[] seed = Base64.getDecoder().decode(seedBase64);
    EdDSAPrivateKeySpec privKeySpec = new EdDSAPrivateKeySpec(seed, keySpecs);
    EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privKeySpec.getA(), keySpecs);
    keys.add(new KeyPair(new EdDSAPublicKey(pubKeySpec), new EdDSAPrivateKey(privKeySpec)));
}
 
开发者ID:kamax-io,项目名称:matrix-java-sdk,代码行数:16,代码来源:KeyManager.java


示例3: build

import net.i2p.crypto.eddsa.KeyPairGenerator; //导入依赖的package包/类
@PostConstruct
public void build() {
    try {
        keySpecs = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512);
        signEngine = new EdDSAEngine(MessageDigest.getInstance(keySpecs.getHashAlgorithm()));
        keys = new ArrayList<>();

        Path privKey = Paths.get(keyCfg.getPath());

        if (!Files.exists(privKey)) {
            KeyPair pair = (new KeyPairGenerator()).generateKeyPair();
            String keyEncoded = Base64.getEncoder().encodeToString(pair.getPrivate().getEncoded());
            FileUtils.writeStringToFile(privKey.toFile(), keyEncoded, StandardCharsets.ISO_8859_1);
            keys.add(pair);
        } else {
            if (Files.isDirectory(privKey)) {
                throw new RuntimeException("Invalid path for private key: " + privKey.toString());
            }

            if (Files.isReadable(privKey)) {
                byte[] seed = Base64.getDecoder().decode(FileUtils.readFileToString(privKey.toFile(), StandardCharsets.ISO_8859_1));
                EdDSAPrivateKeySpec privKeySpec = new EdDSAPrivateKeySpec(seed, keySpecs);
                EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privKeySpec.getA(), keySpecs);
                keys.add(new KeyPair(new EdDSAPublicKey(pubKeySpec), new EdDSAPrivateKey(privKeySpec)));
            }
        }
    } catch (NoSuchAlgorithmException | IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:kamax-io,项目名称:mxisd,代码行数:31,代码来源:KeyManager.java


示例4: setup

import net.i2p.crypto.eddsa.KeyPairGenerator; //导入依赖的package包/类
@Before
public void setup() throws InvalidAlgorithmParameterException {

    config = new SqrlConfig();
    config.setSqrlVersion(SQRL_VERSION);
    config.setNutExpirationSeconds(NUT_EXPIRATION);
    config.setSfn(SFN);
    config.setSqrlBaseUri(SQRL_BASE);

    jSqrlServer = new JSqrlServer(userService, sqrlAuthenticationService, config, nutService);

    when(nutService.createNutFromString(NUT_STRING)).thenReturn(sqrlNut);
    when(nutService.getNutString(sqrlNut)).thenReturn(NUT_STRING);
    when(sqrlNut.getCreated()).thenReturn(LocalDateTime.now().minus(10, ChronoUnit.SECONDS));
    when(sqrlNut.isQr()).thenReturn(true);

    when(nutService.createNut(IP_ADDRESS, true)).thenReturn(sqrlNut2);
    when(nutService.getNutString(sqrlNut2)).thenReturn(NUT_STRING_2);

    when(sqrlUser.sqrlEnabled()).thenReturn(true);

    edDsaSpec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512);
    KeyPairGenerator generator = new KeyPairGenerator();
    generator.initialize(edDsaSpec, new SecureRandom());

    KeyPair keyPair = generator.generateKeyPair();
    clientPrivateKey = keyPair.getPrivate();
    clientPublicKey = keyPair.getPublic();
    byte[] pke = clientPublicKey.getEncoded();
    idk = Arrays.copyOfRange(pke, pke.length - 32, pke.length);
    idkEncoded = SqrlUtil.unpaddedBase64UrlEncoded(idk);
}
 
开发者ID:banichols,项目名称:jsqrl-server,代码行数:33,代码来源:JSqrlServerTest.java


示例5: testHandleClientRequest_ident_by_pidk

import net.i2p.crypto.eddsa.KeyPairGenerator; //导入依赖的package包/类
@Test
public void testHandleClientRequest_ident_by_pidk() throws Exception {

    //Generate a new key pair so we can sign the pidk
    KeyPairGenerator generator = new KeyPairGenerator();
    generator.initialize(edDsaSpec, new SecureRandom());

    KeyPair keyPair = generator.generateKeyPair();
    PrivateKey pidkPrivate = keyPair.getPrivate();
    PublicKey pidkPublic = keyPair.getPublic();
    String pidkEncoded = getEncodedPublicKeyString(pidkPublic);

    when(userService.getUserBySqrlKey(idkEncoded)).thenReturn(null);
    when(userService.getUserBySqrlKey(pidkEncoded)).thenReturn(sqrlUser);

    String clientRequestString = createClientRequestMapString(SQRL_VERSION,
            "ident",
            SqrlUtil.unpaddedBase64UrlEncoded(idk),
            pidkEncoded,
            "suk",
            SERVER_UNLOCK_KEY,
            VERIFY_UNLOCK_KEY);

    SqrlClientRequest request = createClientRequest(clientRequestString, SERVER, clientPrivateKey);

    byte[] pids = signRequest(request.getClient(), request.getServer(), pidkPrivate);
    request.setPids(SqrlUtil.unpaddedBase64UrlEncoded(pids));

    SqrlAuthResponse response = jSqrlServer.handleClientRequest(request, NUT_STRING, IP_ADDRESS);

    assertThat(response.getNut()).isEqualTo(NUT_STRING_2);
    assertThat(response.getVer()).isEqualTo(SQRL_VERSION);
    assertThat(response.getQry()).isEqualTo(SQRL_BASE + "?nut=" + NUT_STRING_2);
    assertResponseTifs(response, TransactionInformationFlag.PREVIOUS_ID_MATCH, TransactionInformationFlag.ID_MATCH);

    verify(sqrlAuthenticationService).linkNut(NUT_STRING, NUT_STRING_2);
    verify(userService).getUserBySqrlKey(idkEncoded);
    verify(userService).getUserBySqrlKey(pidkEncoded);
    verify(userService).updateIdentityKey(pidkEncoded, idkEncoded);
}
 
开发者ID:banichols,项目名称:jsqrl-server,代码行数:41,代码来源:JSqrlServerTest.java


示例6: testHandleClientRequest_ident_by_pidk_invalid_pidk_sig

import net.i2p.crypto.eddsa.KeyPairGenerator; //导入依赖的package包/类
@Test
public void testHandleClientRequest_ident_by_pidk_invalid_pidk_sig() throws Exception {

    //Generate a new key pair so we can sign the pidk
    KeyPairGenerator generator = new KeyPairGenerator();
    generator.initialize(edDsaSpec, new SecureRandom());

    KeyPair keyPair = generator.generateKeyPair();
    PublicKey pidkPublic = keyPair.getPublic();
    String pidkEncoded = getEncodedPublicKeyString(pidkPublic);

    when(userService.getUserBySqrlKey(idkEncoded)).thenReturn(null);
    when(userService.getUserBySqrlKey(pidkEncoded)).thenReturn(sqrlUser);

    String clientRequestString = createClientRequestMapString(SQRL_VERSION,
            "ident",
            SqrlUtil.unpaddedBase64UrlEncoded(idk),
            pidkEncoded,
            "suk",
            SERVER_UNLOCK_KEY,
            VERIFY_UNLOCK_KEY);

    SqrlClientRequest request = createClientRequest(clientRequestString, SERVER, clientPrivateKey);

    //Just use the original ids, it won't be valid
    request.setPids(request.getIds());

    SqrlAuthResponse response = jSqrlServer.handleClientRequest(request, NUT_STRING, IP_ADDRESS);

    assertThat(response.getNut()).isEqualTo(NUT_STRING_2);
    assertThat(response.getVer()).isEqualTo(SQRL_VERSION);
    assertThat(response.getQry()).isEqualTo(SQRL_BASE + "?nut=" + NUT_STRING_2);
    assertResponseTifs(response, TransactionInformationFlag.CLIENT_FAILURE);

    verify(sqrlAuthenticationService, never()).linkNut(NUT_STRING, NUT_STRING_2);
    verify(userService, never()).getUserBySqrlKey(anyString());
    verify(userService, never()).updateIdentityKey(anyString(), anyString());
}
 
开发者ID:banichols,项目名称:jsqrl-server,代码行数:39,代码来源:JSqrlServerTest.java


示例7: testHandleClientRequest_enable_existing_user

import net.i2p.crypto.eddsa.KeyPairGenerator; //导入依赖的package包/类
@Test
public void testHandleClientRequest_enable_existing_user() throws Exception {

    //Generate a new key pair so we can sign the unlock request
    KeyPairGenerator generator = new KeyPairGenerator();
    generator.initialize(edDsaSpec, new SecureRandom());

    KeyPair keyPair = generator.generateKeyPair();
    PublicKey vukPublic = keyPair.getPublic();
    PrivateKey vukPrivate = keyPair.getPrivate();

    String vuk = getEncodedPublicKeyString(vukPublic);

    when(userService.getUserBySqrlKey(idkEncoded)).thenReturn(sqrlUser);
    when(sqrlUser.getVerifyUnlockKey()).thenReturn(vuk);

    String clientRequestString = createClientRequestMapString(SQRL_VERSION,
            "enable",
            SqrlUtil.unpaddedBase64UrlEncoded(idk),
            null,
            "suk",
            null,
            null);

    SqrlClientRequest request = createClientRequest(clientRequestString, SERVER, clientPrivateKey);

    byte[] urs = signRequest(request.getClient(), request.getServer(), vukPrivate);
    request.setUrs(SqrlUtil.unpaddedBase64UrlEncoded(urs));

    SqrlAuthResponse response = jSqrlServer.handleClientRequest(request, NUT_STRING, IP_ADDRESS);

    assertThat(response.getNut()).isEqualTo(NUT_STRING_2);
    assertThat(response.getVer()).isEqualTo(SQRL_VERSION);
    assertThat(response.getQry()).isEqualTo(SQRL_BASE + "?nut=" + NUT_STRING_2);
    assertThat(response.getTif()).isEqualTo(TransactionInformationFlag.ID_MATCH.getHexValue());

    verify(sqrlAuthenticationService).linkNut(NUT_STRING, NUT_STRING_2);
    verify(userService).getUserBySqrlKey(idkEncoded);
    verify(userService).enableSqrlUser(idkEncoded);
}
 
开发者ID:banichols,项目名称:jsqrl-server,代码行数:41,代码来源:JSqrlServerTest.java


示例8: testHandleClientRequest_remove_existing_user

import net.i2p.crypto.eddsa.KeyPairGenerator; //导入依赖的package包/类
@Test
public void testHandleClientRequest_remove_existing_user() throws Exception {

    //Generate a new key pair so we can sign the unlock request
    KeyPairGenerator generator = new KeyPairGenerator();
    generator.initialize(edDsaSpec, new SecureRandom());

    KeyPair keyPair = generator.generateKeyPair();
    PublicKey vukPublic = keyPair.getPublic();
    PrivateKey vukPrivate = keyPair.getPrivate();

    String vuk = getEncodedPublicKeyString(vukPublic);

    when(userService.getUserBySqrlKey(idkEncoded)).thenReturn(sqrlUser);
    when(sqrlUser.getVerifyUnlockKey()).thenReturn(vuk);

    String clientRequestString = createClientRequestMapString(SQRL_VERSION,
            "remove",
            SqrlUtil.unpaddedBase64UrlEncoded(idk),
            null,
            "suk",
            null,
            null);

    SqrlClientRequest request = createClientRequest(clientRequestString, SERVER, clientPrivateKey);

    byte[] urs = signRequest(request.getClient(), request.getServer(), vukPrivate);
    request.setUrs(SqrlUtil.unpaddedBase64UrlEncoded(urs));

    SqrlAuthResponse response = jSqrlServer.handleClientRequest(request, NUT_STRING, IP_ADDRESS);

    assertThat(response.getNut()).isEqualTo(NUT_STRING_2);
    assertThat(response.getVer()).isEqualTo(SQRL_VERSION);
    assertThat(response.getQry()).isEqualTo(SQRL_BASE + "?nut=" + NUT_STRING_2);
    assertThat(response.getTif()).isEqualTo(TransactionInformationFlag.ID_MATCH.getHexValue());

    verify(sqrlAuthenticationService).linkNut(NUT_STRING, NUT_STRING_2);
    verify(userService).getUserBySqrlKey(idkEncoded);
    verify(userService).removeSqrlUser(idkEncoded);
}
 
开发者ID:banichols,项目名称:jsqrl-server,代码行数:41,代码来源:JSqrlServerTest.java


示例9: testUnverifiedSignature

import net.i2p.crypto.eddsa.KeyPairGenerator; //导入依赖的package包/类
@Test
public void testUnverifiedSignature() throws Exception {

    //Generate a new key pair so we generate a valid signature, just one
    //that won't be verified against the original request
    KeyPairGenerator generator = new KeyPairGenerator();
    generator.initialize(edDsaSpec, new SecureRandom());

    KeyPair keyPair = generator.generateKeyPair();
    PrivateKey invalidPrivateKey = keyPair.getPrivate();

    when(userService.getUserBySqrlKey(idkEncoded)).thenReturn(null);

    String clientRequestString = createClientRequestMapString(SQRL_VERSION,
            "query",
            SqrlUtil.unpaddedBase64UrlEncoded(idk),
            "suk",
            null,
            null,
            null);

    SqrlClientRequest request = createClientRequest(clientRequestString, SERVER, invalidPrivateKey);

    SqrlAuthResponse response = jSqrlServer.handleClientRequest(request, NUT_STRING, IP_ADDRESS);

    assertThat(response.getNut()).isEqualTo(NUT_STRING_2);
    assertThat(response.getVer()).isEqualTo(SQRL_VERSION);
    assertThat(response.getQry()).isEqualTo(SQRL_BASE + "?nut=" + NUT_STRING_2);
    assertResponseTifs(response, TransactionInformationFlag.CLIENT_FAILURE);

    /**TODO Is it valid to assume we shouldn't link a request with a bad signature to one that had a good signature?*/
    verify(sqrlAuthenticationService, never()).linkNut(NUT_STRING, NUT_STRING_2);
    verify(userService, never()).getUserBySqrlKey(idkEncoded);
}
 
开发者ID:banichols,项目名称:jsqrl-server,代码行数:35,代码来源:JSqrlServerTest.java


示例10: random

import net.i2p.crypto.eddsa.KeyPairGenerator; //导入依赖的package包/类
/**
 * Generates a random Stellar keypair.
 * @return a random Stellar keypair.
 */
public static KeyPair random() {
  java.security.KeyPair keypair = new KeyPairGenerator().generateKeyPair();
  return new KeyPair((EdDSAPublicKey) keypair.getPublic(), (EdDSAPrivateKey) keypair.getPrivate());
}
 
开发者ID:stellar,项目名称:java-stellar-sdk,代码行数:9,代码来源:KeyPair.java


示例11: generateNewAuthToken

import net.i2p.crypto.eddsa.KeyPairGenerator; //导入依赖的package包/类
/**
 * Use this method once to generated an "authToken" which is the
 * combination of a random "user" and the hash of an EdDSA-key.
 * Persist the authToken somewhere, either in a static final, inside a property etc.
 *
 * @return An authToken to be used with the constructor of AirPlayAuth.
 */
public static String generateNewAuthToken() {
    String clientId = AuthUtils.randomString(16);

    return clientId + "@" + net.i2p.crypto.eddsa.Utils.bytesToHex(new KeyPairGenerator().generateKeyPair().getPrivate().getEncoded());
}
 
开发者ID:funtax,项目名称:AirPlayAuth,代码行数:13,代码来源:AirPlayAuth.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ThreadSafeClientConnManager类代码示例发布时间:2022-05-22
下一篇:
Java Type类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap