org.springframework.security.crypto.codec.Hex.decode()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(129)

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

Hex.decode介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-security

private byte[] decode(CharSequence encodedPassword) {
  return Hex.decode(encodedPassword);
}

代码示例来源:origin: spring-projects/spring-security

private byte[] decode(String encodedBytes) {
  if (this.encodeHashAsBase64) {
    return Base64.getDecoder().decode(encodedBytes);
  }
  return Hex.decode(encodedBytes);
}

代码示例来源:origin: org.springframework.security/spring-security-core

private byte[] decode(String encodedBytes) {
  if (this.encodeHashAsBase64) {
    return Base64.getDecoder().decode(encodedBytes);
  }
  return Hex.decode(encodedBytes);
}

代码示例来源:origin: spring-projects/spring-security

public AesBytesEncryptor(String password, CharSequence salt,
    BytesKeyGenerator ivGenerator, CipherAlgorithm alg) {
  PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray(), Hex.decode(salt),
      1024, 256);
  SecretKey secretKey = newSecretKey("PBKDF2WithHmacSHA1", keySpec);
  this.secretKey = new SecretKeySpec(secretKey.getEncoded(), "AES");
  this.alg = alg;
  this.encryptor = alg.createCipher();
  this.decryptor = alg.createCipher();
  this.ivGenerator = ivGenerator != null ? ivGenerator : alg.defaultIvGenerator();
}

代码示例来源:origin: spring-projects/spring-security

public String decrypt(String encryptedText) {
  return Utf8.decode(encryptor.decrypt(Hex.decode(encryptedText)));
}

代码示例来源:origin: org.springframework.security/spring-security-core

public AesBytesEncryptor(String password, CharSequence salt,
    BytesKeyGenerator ivGenerator, CipherAlgorithm alg) {
  PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray(), Hex.decode(salt),
      1024, 256);
  SecretKey secretKey = newSecretKey("PBKDF2WithHmacSHA1", keySpec);
  this.secretKey = new SecretKeySpec(secretKey.getEncoded(), "AES");
  this.alg = alg;
  this.encryptor = alg.createCipher();
  this.decryptor = alg.createCipher();
  this.ivGenerator = ivGenerator != null ? ivGenerator : alg.defaultIvGenerator();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void hexDecode() {
  byte[] bytes = new byte[] { (byte) 0x01, (byte) 0xFF, (byte) 65, (byte) 66,
    (byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
  byte[] result = Hex.decode("01ff414243c0c1c2");
  assertThat(Arrays.equals(bytes, result)).isTrue();
}

代码示例来源:origin: spring-projects/spring-security

BouncyCastleAesBytesEncryptor(String password, CharSequence salt,
      BytesKeyGenerator ivGenerator) {
    if (ivGenerator.getKeyLength() != 16) {
      throw new IllegalArgumentException("ivGenerator key length != block size 16");
    }
    this.ivGenerator = ivGenerator;
    PBEParametersGenerator keyGenerator = new PKCS5S2ParametersGenerator();
    byte[] pkcs12PasswordBytes = PBEParametersGenerator
        .PKCS5PasswordToUTF8Bytes(password.toCharArray());
    keyGenerator.init(pkcs12PasswordBytes, Hex.decode(salt), 1024);
    this.secretKey = (KeyParameter) keyGenerator.generateDerivedParameters(256);
  }
}

代码示例来源:origin: org.springframework.security/spring-security-core

BouncyCastleAesBytesEncryptor(String password, CharSequence salt,
      BytesKeyGenerator ivGenerator) {
    if (ivGenerator.getKeyLength() != 16) {
      throw new IllegalArgumentException("ivGenerator key length != block size 16");
    }
    this.ivGenerator = ivGenerator;
    PBEParametersGenerator keyGenerator = new PKCS5S2ParametersGenerator();
    byte[] pkcs12PasswordBytes = PBEParametersGenerator
        .PKCS5PasswordToUTF8Bytes(password.toCharArray());
    keyGenerator.init(pkcs12PasswordBytes, Hex.decode(salt), 1024);
    this.secretKey = (KeyParameter) keyGenerator.generateDerivedParameters(256);
  }
}

代码示例来源:origin: spring-projects/spring-security

@Override
public boolean matches(CharSequence rawPassword, String encodedPassword) {
  byte[] digested = Hex.decode(encodedPassword);
  byte[] salt = subArray(digested, 0, this.saltGenerator.getKeyLength());
  return matches(digested, encodeAndConcatenate(rawPassword, salt));
}

代码示例来源:origin: spring-projects/spring-security

@Before
public void setUp() {
  this.generator = mock(BytesKeyGenerator.class);
  when(this.generator.generateKey()).thenReturn(Hex.decode("4b0febebd439db7ca77153cb254520c3"));
  when(this.generator.getKeyLength()).thenReturn(16);
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void decode() {
  assertThat(Hex.decode("41424344")).isEqualTo(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C',
    (byte) 'D' });
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void decodeEmptyString() {
  assertThat(Hex.decode("")).isEmpty();
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void string() {
  StringKeyGenerator keyGenerator = KeyGenerators.string();
  String hexStringKey = keyGenerator.generateKey();
  assertThat(hexStringKey.length()).isEqualTo(16);
  assertThat(Hex.decode(hexStringKey)).hasSize(8);
  String hexStringKey2 = keyGenerator.generateKey();
  assertThat(hexStringKey.equals(hexStringKey2)).isFalse();
}

代码示例来源:origin: org.springframework.security/spring-security-core

@Override
public boolean matches(CharSequence rawPassword, String encodedPassword) {
  byte[] digested = Hex.decode(encodedPassword);
  byte[] salt = subArray(digested, 0, this.saltGenerator.getKeyLength());
  return matches(digested, encodeAndConcatenate(rawPassword, salt));
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void migrate() {
  final int saltLength = KeyGenerators.secureRandom().getKeyLength();
  String encodedPassword = "ab1146a8458d4ce4e65789e5a3f60e423373cfa10b01abd23739e5ae2fdc37f8e9ede4ae6da65264";
  String originalEncodedPassword = "ab1146a8458d4ce4ab1146a8458d4ce4e65789e5a3f60e423373cfa10b01abd23739e5ae2fdc37f8e9ede4ae6da65264";
  byte[] originalBytes = Hex.decode(originalEncodedPassword);
  byte[] fixedBytes = Arrays.copyOfRange(originalBytes, saltLength,
      originalBytes.length);
  String fixedHex = String.valueOf(Hex.encode(fixedBytes));
  assertThat(fixedHex).isEqualTo(encodedPassword);
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void decodeNotEven() {
  expectedException.expect(IllegalArgumentException.class);
  expectedException.expectMessage("Hex-encoded string must have an even number of characters");
  Hex.decode("414243444");
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void decodeExistNonHexCharAtBoth() {
  expectedException.expect(IllegalArgumentException.class);
  expectedException.expectMessage("Detected a Non-hex character at 5 or 6 position");
  Hex.decode("4142GG");
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void decodeExistNonHexCharAtSecond() {
  expectedException.expect(IllegalArgumentException.class);
  expectedException.expectMessage("Detected a Non-hex character at 3 or 4 position");
  Hex.decode("410G");
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void decodeExistNonHexCharAtFirst() {
  expectedException.expect(IllegalArgumentException.class);
  expectedException.expectMessage("Detected a Non-hex character at 1 or 2 position");
  Hex.decode("G0");
}

相关文章

微信公众号

最新文章

更多