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


Java KeyPairGenerator.generateKeyPair方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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


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