com.auth0.jwt.algorithms.Algorithm.ECDSA512()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(192)

本文整理了Java中com.auth0.jwt.algorithms.Algorithm.ECDSA512()方法的一些代码示例,展示了Algorithm.ECDSA512()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Algorithm.ECDSA512()方法的具体详情如下:
包路径:com.auth0.jwt.algorithms.Algorithm
类名称:Algorithm
方法名:ECDSA512

Algorithm.ECDSA512介绍

[英]Creates a new Algorithm instance using SHA512withECDSA. Tokens specify this as "ES512".
[中]使用SHA512withECDSA创建新的算法实例。令牌将其指定为“ES512”。

代码示例

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldCreateECDSA512AlgorithmWithBothKeys() throws Exception {
  ECPublicKey publicKey = mock(ECPublicKey.class);
  ECPrivateKey privateKey = mock(ECPrivateKey.class);
  Algorithm algorithm = Algorithm.ECDSA512(publicKey, privateKey);
  assertThat(algorithm, is(notNullValue()));
  assertThat(algorithm, is(instanceOf(ECDSAAlgorithm.class)));
  assertThat(algorithm.getDescription(), is("SHA512withECDSA"));
  assertThat(algorithm.getName(), is("ES512"));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldCreateECDSA512AlgorithmWithProvider() throws Exception {
  ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
  Algorithm algorithm = Algorithm.ECDSA512(provider);
  assertThat(algorithm, is(notNullValue()));
  assertThat(algorithm, is(instanceOf(ECDSAAlgorithm.class)));
  assertThat(algorithm.getDescription(), is("SHA512withECDSA"));
  assertThat(algorithm.getName(), is("ES512"));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldPassECDSA512VerificationWithProvidedPublicKey() throws Exception {
  ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
  PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC");
  when(provider.getPublicKeyById("my-key-id")).thenReturn((ECPublicKey) publicKey);
  String jwt = "eyJhbGciOiJFUzUxMiIsImtpZCI6Im15LWtleS1pZCJ9.eyJpc3MiOiJhdXRoMCJ9.AGxEwbsYa2bQ7Y7DAcTQnVD8PmLSlhJ20jg2OfdyPnqdXI8SgBaG6lGciq3_pofFhs1HEoFoJ33Jcluha24oMHIvAfwu8qbv_Wq3L2eI9Q0L0p6ul8Pd_BS8adRa2PgLc36xXGcRc7ID5YH-CYaQfsTp5YIaF0Po3h0QyCoQ6ZiYQkqm";
  Algorithm algorithm = Algorithm.ECDSA512(provider);
  algorithm.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldCreateECDSA512AlgorithmWithPublicKey() throws Exception {
  ECKey key = mock(ECKey.class, withSettings().extraInterfaces(ECPublicKey.class));
  Algorithm algorithm = Algorithm.ECDSA512(key);
  assertThat(algorithm, is(notNullValue()));
  assertThat(algorithm, is(instanceOf(ECDSAAlgorithm.class)));
  assertThat(algorithm.getDescription(), is("SHA512withECDSA"));
  assertThat(algorithm.getName(), is("ES512"));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldFailECDSA512VerificationOnInvalidJOSESignature() throws Exception {
  exception.expect(SignatureVerificationException.class);
  exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA512withECDSA");
  byte[] bytes = new byte[132];
  new SecureRandom().nextBytes(bytes);
  String signature = Base64.encodeBase64URLSafeString(bytes);
  String jwt = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9." + signature;
  Algorithm algorithm = Algorithm.ECDSA512((ECKey) readPublicKeyFromFile(INVALID_PUBLIC_KEY_FILE_512, "EC"));
  algorithm.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldThrowECDSA512InstanceWithNullKeyProvider() throws Exception {
  exception.expect(IllegalArgumentException.class);
  exception.expectMessage("The Key Provider cannot be null.");
  ECDSAKeyProvider provider = null;
  Algorithm.ECDSA512(provider);
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldDoECDSA512SigningWithProvidedPrivateKey() throws Exception {
  ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
  PrivateKey privateKey = readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC");
  PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC");
  when(provider.getPrivateKey()).thenReturn((ECPrivateKey) privateKey);
  when(provider.getPublicKeyById(null)).thenReturn((ECPublicKey) publicKey);
  Algorithm algorithm = Algorithm.ECDSA512(provider);
  String jwt = asJWT(algorithm, ES512Header, auth0IssPayload);
  assertSignaturePresent(jwt);
  algorithm.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldDoECDSA512SigningWithProvidedPrivateKey() throws Exception {
  ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
  PrivateKey privateKey = readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC");
  PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC");
  when(provider.getPrivateKey()).thenReturn((ECPrivateKey) privateKey);
  when(provider.getPublicKeyById(null)).thenReturn((ECPublicKey) publicKey);
  Algorithm algorithm = Algorithm.ECDSA512(provider);
  
  String jwt = asJWT(algorithm, ES512Header, auth0IssPayload);
  assertSignaturePresent(jwt);
  algorithm.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldDoECDSA512Signing() throws Exception {
  Algorithm algorithmSign = Algorithm.ECDSA512((ECKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC"));
  Algorithm algorithmVerify = Algorithm.ECDSA512((ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC"));
  
  String jwt = asJWT(algorithmSign, ES512Header, auth0IssPayload);
  assertSignaturePresent(jwt);
  algorithmVerify.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldDoECDSA512Signing() throws Exception {
  Algorithm algorithmSign = Algorithm.ECDSA512((ECKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC"));
  Algorithm algorithmVerify = Algorithm.ECDSA512((ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC"));
  
  String jwt = asJWT(algorithmSign, ES512Header, auth0IssPayload);
  assertSignaturePresent(jwt);
  algorithmVerify.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldAcceptECDSA512Algorithm() throws Exception {
  String token = "eyJhbGciOiJFUzUxMiJ9.eyJpc3MiOiJhdXRoMCJ9.AeCJPDIsSHhwRSGZCY6rspi8zekOw0K9qYMNridP1Fu9uhrA1QrG-EUxXlE06yvmh2R7Rz0aE7kxBwrnq8L8aOBCAYAsqhzPeUvyp8fXjjgs0Eto5I0mndE2QHlgcMSFASyjHbU8wD2Rq7ZNzGQ5b2MZfpv030WGUajT-aZYWFUJHVg2";
  ECKey key = (ECKey) PemUtils.readPublicKeyFromFile(PUBLIC_KEY_FILE_EC_512, "EC");
  DecodedJWT jwt = JWT.require(Algorithm.ECDSA512(key))
      .build()
      .verify(token);
  assertThat(jwt, is(notNullValue()));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldPassECDSA512VerificationWithJOSESignature() throws Exception {
  String jwt = "eyJhbGciOiJFUzUxMiJ9.eyJpc3MiOiJhdXRoMCJ9.AeCJPDIsSHhwRSGZCY6rspi8zekOw0K9qYMNridP1Fu9uhrA1QrG-EUxXlE06yvmh2R7Rz0aE7kxBwrnq8L8aOBCAYAsqhzPeUvyp8fXjjgs0Eto5I0mndE2QHlgcMSFASyjHbU8wD2Rq7ZNzGQ5b2MZfpv030WGUajT-aZYWFUJHVg2";
  ECKey key = (ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC");
  Algorithm algorithm = Algorithm.ECDSA512(key);
  algorithm.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldPassECDSA512VerificationWithJOSESignatureWithBothKeys() throws Exception {
  String jwt = "eyJhbGciOiJFUzUxMiJ9.eyJpc3MiOiJhdXRoMCJ9.AeCJPDIsSHhwRSGZCY6rspi8zekOw0K9qYMNridP1Fu9uhrA1QrG-EUxXlE06yvmh2R7Rz0aE7kxBwrnq8L8aOBCAYAsqhzPeUvyp8fXjjgs0Eto5I0mndE2QHlgcMSFASyjHbU8wD2Rq7ZNzGQ5b2MZfpv030WGUajT-aZYWFUJHVg2";
  Algorithm algorithm = Algorithm.ECDSA512((ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC"), (ECPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC"));
  algorithm.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldPassECDSA512VerificationWithJOSESignatureWithBothKeys() throws Exception {
  String jwt = "eyJhbGciOiJFUzUxMiJ9.eyJpc3MiOiJhdXRoMCJ9.AeCJPDIsSHhwRSGZCY6rspi8zekOw0K9qYMNridP1Fu9uhrA1QrG-EUxXlE06yvmh2R7Rz0aE7kxBwrnq8L8aOBCAYAsqhzPeUvyp8fXjjgs0Eto5I0mndE2QHlgcMSFASyjHbU8wD2Rq7ZNzGQ5b2MZfpv030WGUajT-aZYWFUJHVg2";
  Algorithm algorithm = Algorithm.ECDSA512((ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC"), (ECPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC"));
  algorithm.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldSignAndVerifyWithECDSA512() throws Exception {
  ECDSAAlgorithm algorithm512 = (ECDSAAlgorithm) Algorithm.ECDSA512((ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC"), (ECPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC"));
  String header512 = "eyJhbGciOiJFUzUxMiJ9";
  String body = "eyJpc3MiOiJhdXRoMCJ9";        
  for (int i = 0; i < 10; i++) {
    String jwt = asJWT(algorithm512, header512, body);
    algorithm512.verify(JWT.decode(jwt));
  }
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldFailECDSA512VerificationWithInvalidPublicKey() throws Exception {
  exception.expect(SignatureVerificationException.class);
  exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA512withECDSA");
  String jwt = "eyJhbGciOiJFUzUxMiJ9.eyJpc3MiOiJhdXRoMCJ9.AZgdopFFsN0amCSs2kOucXdpylD31DEm5ChK1PG0_gq5Mf47MrvVph8zHSVuvcrXzcE1U3VxeCg89mYW1H33Y-8iAF0QFkdfTUQIWKNObH543WNMYYssv3OtOj0znPv8atDbaF8DMYAtcT1qdmaSJRhx-egRE9HGZkinPh9CfLLLt58X";
  Algorithm algorithm = Algorithm.ECDSA512((ECKey) readPublicKeyFromFile(INVALID_PUBLIC_KEY_FILE_512, "EC"));
  algorithm.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
  public void shouldPassECDSA512VerificationWithJOSESignature() throws Exception {
    String token = "eyJhbGciOiJFUzUxMiJ9.eyJpc3MiOiJhdXRoMCJ9.AeCJPDIsSHhwRSGZCY6rspi8zekOw0K9qYMNridP1Fu9uhrA1QrG-EUxXlE06yvmh2R7Rz0aE7kxBwrnq8L8aOBCAYAsqhzPeUvyp8fXjjgs0Eto5I0mndE2QHlgcMSFASyjHbU8wD2Rq7ZNzGQ5b2MZfpv030WGUajT-aZYWFUJHVg2";
    ECKey key = (ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC");
    Algorithm algorithm = Algorithm.ECDSA512(key);
    JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();

    concurrentVerify(verifier, token);
  }
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldFailECDSA512VerificationWhenUsingPrivateKey() throws Exception {
  exception.expect(SignatureVerificationException.class);
  exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA512withECDSA");
  exception.expectCause(isA(IllegalStateException.class));
  exception.expectCause(hasMessage(is("The given Public Key is null.")));
  String jwt = "eyJhbGciOiJFUzUxMiJ9.eyJpc3MiOiJhdXRoMCJ9.AZgdopFFsN0amCSs2kOucXdpylD31DEm5ChK1PG0_gq5Mf47MrvVph8zHSVuvcrXzcE1U3VxeCg89mYW1H33Y-8iAF0QFkdfTUQIWKNObH543WNMYYssv3OtOj0znPv8atDbaF8DMYAtcT1qdmaSJRhx-egRE9HGZkinPh9CfLLLt58X";
  Algorithm algorithm = Algorithm.ECDSA512((ECKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC"));
  algorithm.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldFailECDSA512VerificationWhenUsingPrivateKey() throws Exception {
  exception.expect(SignatureVerificationException.class);
  exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA512withECDSA");
  exception.expectCause(isA(IllegalStateException.class));
  exception.expectCause(hasMessage(is("The given Public Key is null.")));
  String jwt = "eyJhbGciOiJFUzUxMiJ9.eyJpc3MiOiJhdXRoMCJ9.AZgdopFFsN0amCSs2kOucXdpylD31DEm5ChK1PG0_gq5Mf47MrvVph8zHSVuvcrXzcE1U3VxeCg89mYW1H33Y-8iAF0QFkdfTUQIWKNObH543WNMYYssv3OtOj0znPv8atDbaF8DMYAtcT1qdmaSJRhx-egRE9HGZkinPh9CfLLLt58X";
  Algorithm algorithm = Algorithm.ECDSA512((ECKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC"));
  algorithm.verify(JWT.decode(jwt));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldDoECDSA512SigningWithBothKeys() throws Exception {
  Algorithm algorithm = Algorithm.ECDSA512((ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC"), (ECPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC"));
  
  String jwt = asJWT(algorithm, ES512Header, auth0IssPayload);
  assertSignaturePresent(jwt);
  algorithm.verify(JWT.decode(jwt));
}

相关文章