org.apache.shiro.codec.Hex.encodeToString()方法的使用及代码示例

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

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

Hex.encodeToString介绍

[英]Encodes the specified byte array to a character array and then returns that character array as a String.
[中]将指定的字节数组编码为字符数组,然后将该字符数组作为字符串返回。

代码示例

代码示例来源:origin: Graylog2/graylog2-server

@Nullable
public static String encrypt(String plainText, String encryptionKey, String salt) {
  try {
    @SuppressWarnings("CIPHER_INTEGRITY")
    Cipher cipher = Cipher.getInstance("AES/CBC/ISO10126Padding", "SunJCE");
    SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES");
    cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(salt.getBytes("UTF-8")));
    return Hex.encodeToString(cipher.doFinal(plainText.getBytes("UTF-8")));
  } catch (Exception e) {
    LOG.error("Could not encrypt value.", e);
  }
  return null;
}

代码示例来源:origin: apache/shiro

public String toHex() {
  if ( this.cachedHex == null ) {
    this.cachedHex = Hex.encodeToString(getBytes());
  }
  return this.cachedHex;
}

代码示例来源:origin: apache/shiro

/**
 * Returns a hex-encoded string of the underlying {@link #getBytes byte array}.
 * <p/>
 * This implementation caches the resulting hex string so multiple calls to this method remain efficient.
 * However, calling {@link #setBytes setBytes} will null the cached value, forcing it to be recalculated the
 * next time this method is called.
 *
 * @return a hex-encoded string of the underlying {@link #getBytes byte array}.
 */
public String toHex() {
  if (this.hexEncoded == null) {
    this.hexEncoded = Hex.encodeToString(getBytes());
  }
  return this.hexEncoded;
}

代码示例来源:origin: apache/shiro

/**
 * Returns a hex-encoded string of the underlying {@link #getBytes byte array}.
 * <p/>
 * This implementation caches the resulting hex string so multiple calls to this method remain efficient.
 * However, calling {@link #setBytes setBytes} will null the cached value, forcing it to be recalculated the
 * next time this method is called.
 *
 * @return a hex-encoded string of the underlying {@link #getBytes byte array}.
 */
public String toHex() {
  if (this.hexEncoded == null) {
    this.hexEncoded = Hex.encodeToString(getBytes());
  }
  return this.hexEncoded;
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public void setSystemPassword(String systemPassword) {
  if (systemPassword == null || systemPassword.isEmpty()) {
    return;
  }
  // set new salt value, if we didn't have any.
  if (getSystemPasswordSalt().isEmpty()) {
    LOG.debug("Generating new salt for LDAP system password.");
    final SecureRandom random = new SecureRandom();
    byte[] saltBytes = new byte[8];
    random.nextBytes(saltBytes);
    setSystemPasswordSalt(Hex.encodeToString(saltBytes));
  }
  final String encrypted = AESTools.encrypt(
      systemPassword,
      configuration.getPasswordSecret().substring(0, 16),
      getSystemPasswordSalt());
  fields.put(SYSTEM_PASSWORD, encrypted);
}

代码示例来源:origin: org.graylog2/graylog2-server

@Nullable
public static String encrypt(String plainText, String encryptionKey, String salt) {
  try {
    @SuppressWarnings("CIPHER_INTEGRITY")
    Cipher cipher = Cipher.getInstance("AES/CBC/ISO10126Padding", "SunJCE");
    SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES");
    cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(salt.getBytes("UTF-8")));
    return Hex.encodeToString(cipher.doFinal(plainText.getBytes("UTF-8")));
  } catch (Exception e) {
    LOG.error("Could not encrypt value.", e);
  }
  return null;
}

代码示例来源:origin: org.apache.shiro/shiro-lang

public String toHex() {
  if ( this.cachedHex == null ) {
    this.cachedHex = Hex.encodeToString(getBytes());
  }
  return this.cachedHex;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

public String toHex() {
  if ( this.cachedHex == null ) {
    this.cachedHex = Hex.encodeToString(getBytes());
  }
  return this.cachedHex;
}

代码示例来源:origin: TomChen001/xmanager

@Override
public String toHex() {
  if ( this.cachedHex == null ) {
    this.cachedHex = Hex.encodeToString(getBytes());
  }
  return this.cachedHex;
}

代码示例来源:origin: dschadow/JavaSecurity

private static void printReadableMessages(String initialText, byte[] ciphertext, byte[] plaintext) {
    log.info("initialText: {}", initialText);
    log.info("cipherText as HEX: {}", Hex.encodeToString(ciphertext));
    log.info("plaintext: {}", CodecSupport.toString(plaintext));
  }
}

代码示例来源:origin: SomMeri/matasano-cryptopals-solutions

private long averageTime(Ex32Browser browser, String filename, byte[] signature) {
  long total = 0;
  long samples = EX_32_SAMPLES;
  for (int i = 0; i < samples; i++) {
   total += browser.measureValidationLength(filename, Hex.encodeToString(signature));
  }
  return total / samples;
 }
}

代码示例来源:origin: org.codeartisans.shiro/shiro-ext-x509-web

private String readHexSerialNumberFromString( String input )
{
  return Hex.encodeToString( Hex.decode( input ) ); // FIXME Upstream Hex implementation is not char encoding safe, fix it there
}

代码示例来源:origin: SomMeri/matasano-cryptopals-solutions

public String base64ToHex(String base64) {
 byte[] raw = Base64.decode(base64);
 return Hex.encodeToString(raw);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

/**
 * Returns a hex-encoded string of the underlying {@link #getBytes byte array}.
 * <p/>
 * This implementation caches the resulting hex string so multiple calls to this method remain efficient.
 * However, calling {@link #setBytes setBytes} will null the cached value, forcing it to be recalculated the
 * next time this method is called.
 *
 * @return a hex-encoded string of the underlying {@link #getBytes byte array}.
 */
public String toHex() {
  if (this.hexEncoded == null) {
    this.hexEncoded = Hex.encodeToString(getBytes());
  }
  return this.hexEncoded;
}

代码示例来源:origin: SomMeri/matasano-cryptopals-solutions

public BigInteger hash(byte[] message) {
 String hexadecimalHash = Hex.encodeToString(SHA1.encode(message));
 return new BigInteger(hexadecimalHash, 16);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

/**
 * Returns a hex-encoded string of the underlying {@link #getBytes byte array}.
 * <p/>
 * This implementation caches the resulting hex string so multiple calls to this method remain efficient.
 * However, calling {@link #setBytes setBytes} will null the cached value, forcing it to be recalculated the
 * next time this method is called.
 *
 * @return a hex-encoded string of the underlying {@link #getBytes byte array}.
 */
public String toHex() {
  if (this.hexEncoded == null) {
    this.hexEncoded = Hex.encodeToString(getBytes());
  }
  return this.hexEncoded;
}

代码示例来源:origin: org.apache.shiro/shiro-crypto-hash

/**
 * Returns a hex-encoded string of the underlying {@link #getBytes byte array}.
 * <p/>
 * This implementation caches the resulting hex string so multiple calls to this method remain efficient.
 * However, calling {@link #setBytes setBytes} will null the cached value, forcing it to be recalculated the
 * next time this method is called.
 *
 * @return a hex-encoded string of the underlying {@link #getBytes byte array}.
 */
public String toHex() {
  if (this.hexEncoded == null) {
    this.hexEncoded = Hex.encodeToString(getBytes());
  }
  return this.hexEncoded;
}

代码示例来源:origin: SomMeri/matasano-cryptopals-solutions

public String xorHex(String first, String second) {
 return Hex.encodeToString(xor(Hex.decode(first), Hex.decode(second)));
}

代码示例来源:origin: SomMeri/matasano-cryptopals-solutions

/** Exercise 5 */
public String xorThem(String cipher, String key) {
 return Hex.encodeToString(xor.xor(CodecSupport.toBytes(cipher), CodecSupport.toBytes(key)));
}

代码示例来源:origin: dschadow/JavaSecurity

private static boolean verifyPassword(byte[] originalHash, ByteSource publicSalt, String password) {
    ByteSource privateSalt = ByteSource.Util.bytes(PRIVATE_SALT_BYTES);
    DefaultHashService hashService = new DefaultHashService();
    hashService.setPrivateSalt(privateSalt);
    hashService.setHashIterations(ITERATIONS);

    HashRequest.Builder builder = new HashRequest.Builder();
    builder.setSource(ByteSource.Util.bytes(password));
    builder.setSalt(publicSalt);

    Hash comparisonHash = hashService.computeHash(builder.build());

    log.info("password: {}", password);
    log.info("1 hash: {}", Hex.encodeToString(originalHash));
    log.info("2 hash: {}", comparisonHash.toHex());

    return Arrays.equals(originalHash, comparisonHash.getBytes());
  }
}

相关文章