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


Java Hex类代码示例

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


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

示例1: testAesCipherService

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
@Test
public void testAesCipherService(){
    AesCipherService aesCipherService = new AesCipherService();
    //设置key长度
    aesCipherService.setKeySize(128);

    Key key = aesCipherService.generateNewKey();

    String text = "hello";

    //加密
    String encrpText = aesCipherService.encrypt(text.getBytes(), key.getEncoded()).toHex();
    //解密
    String text2 = new String(aesCipherService.decrypt(Hex.decode(encrpText), key.getEncoded()).getBytes());

    Assert.assertEquals(text, text2);
}
 
开发者ID:l81893521,项目名称:shiro-demo,代码行数:18,代码来源:CodecAndCryptoTest.java

示例2: getCredentials

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
/**
 *
 * @param info the AuthenticationInfo from which to retrieve the credentials which assumed to be in already-hashed form.
 * @return a {@link Hash Hash} instance representing the given AuthenticationInfo's stored credentials.
 */
protected Object getCredentials(AuthenticationInfo info) {
    Object credentials = info.getCredentials();

    byte[] storedBytes = toBytes(credentials);

    if (credentials instanceof String || credentials instanceof char[]) {
        //account.credentials were a char[] or String, so
        //we need to do text decoding first:
        if (isStoredCredentialsHexEncoded()) {
            storedBytes = Hex.decode(storedBytes);
        } else {
            storedBytes = Base64.decode(storedBytes);
        }
    }
    AbstractHash hash = newHashInstance();
    hash.setBytes(storedBytes);
    return hash;
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:24,代码来源:HashedCredentialsMatcher.java

示例3: main

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
public static void main(String[] args) { 
    String password = "admin"; 
    String cipherText = encrytHex(password); 
    System.out.println(password + "hex加密之后的密文是:" + cipherText); 
    String decrptPassword=decryptHex(cipherText); 
    System.out.println(cipherText + "hex解密之后的密码是:" + decrptPassword); 
    String cipherText_base64 = encrytBase64(password); 
    System.out.println(password + "base64加密之后的密文是:" + cipherText_base64); 
    String decrptPassword_base64=decryptBase64(cipherText_base64); 
    System.out.println(cipherText_base64 + "base64解密之后的密码是:" + decrptPassword_base64); 
    String h64=  H64.encodeToString(password.getBytes()); 
    System.out.println(h64); 
    String salt="7road"; 
    String cipherText_md5= new Md5Hash(password,salt,4).toHex(); 
    System.out.println(password+"通过md5加密之后的密文是:"+cipherText_md5); 
    System.out.println(generateKey()); 
    System.out.println("=========================================================="); 
    AesCipherService aesCipherService=new AesCipherService(); 
    aesCipherService.setKeySize(128); 
    Key key=aesCipherService.generateNewKey(); 
    String aes_cipherText= aesCipherService.encrypt(password.getBytes(),key.getEncoded()).toHex(); 
    System.out.println(password+" aes加密的密文是:"+aes_cipherText); 
    String aes_mingwen=new String(aesCipherService.decrypt(Hex.decode(aes_cipherText),key.getEncoded()).getBytes()); 
    System.out.println(aes_cipherText+" aes解密的明文是:"+aes_mingwen); 
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:26,代码来源:EndecryptUtils.java

示例4: testBlowfishCipherService

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
@Test
public void testBlowfishCipherService(){
    BlowfishCipherService blowfishCipherService = new BlowfishCipherService();
    blowfishCipherService.setKeySize(128);

    Key key = blowfishCipherService.generateNewKey();

    String text = "hello";

    //加密
    String encrp = blowfishCipherService.encrypt(text.getBytes(), key.getEncoded()).toHex();
    //解密
    String text2 = new String(blowfishCipherService.decrypt(Hex.decode(encrp), key.getEncoded()).getBytes());

    Assert.assertEquals(text, text2);
}
 
开发者ID:l81893521,项目名称:shiro-demo,代码行数:17,代码来源:CodecAndCryptoTest.java

示例5: testDefaultBlockCipherService

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
@Test
public void testDefaultBlockCipherService(){
    //对称加密,使用Java的JCA(javax.crypto.Cipher)加密API,常见的如 'AES', 'Blowfish'
    DefaultBlockCipherService blockCipherService = new DefaultBlockCipherService("AES");
    blockCipherService.setKeySize(128);

    Key key = blockCipherService.generateNewKey();

    String text = "hello";
    //加密
    String encrp = blockCipherService.encrypt(text.getBytes(), key.getEncoded()).toHex();
    //解密
    String text2 = new String(blockCipherService.decrypt(Hex.decode(encrp), key.getEncoded()).getBytes());

    Assert.assertEquals(text, text2);
}
 
开发者ID:l81893521,项目名称:shiro-demo,代码行数:17,代码来源:CodecAndCryptoTest.java

示例6: verifyPassword

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
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());
}
 
开发者ID:dschadow,项目名称:JavaSecurity,代码行数:19,代码来源:SHA512.java

示例7: decryptAES

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
/**
 * AES解密
 *
 * @param content
 * @return
 */

public static String decryptAES(String content) {
    AesCipherService aesCipherService = new AesCipherService();
    aesCipherService.setKeySize(128);
    return new String(aesCipherService.decrypt(Hex.decode(content), key.getEncoded()).getBytes());
}
 
开发者ID:melonlee,项目名称:LazyREST,代码行数:13,代码来源:EndecryptUtil.java

示例8: toHex

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
@Override
public String toHex() {
	if ( this.cachedHex == null ) {
		this.cachedHex = Hex.encodeToString(getBytes());
	}
	return this.cachedHex;
}
 
开发者ID:TomChen001,项目名称:xmanager,代码行数:8,代码来源:ShiroByteSource.java

示例9: testHex

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
@Test
public void testHex(){
    String str = "hello";
    String hexEncode = Hex.encodeToString(str.getBytes());
    String str2 = new String(Hex.decode(hexEncode.getBytes()));
    Assert.assertEquals(str, str2);
}
 
开发者ID:l81893521,项目名称:shiro-demo,代码行数:8,代码来源:CodecAndCryptoTest.java

示例10: toBytes

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
protected byte[] toBytes(String sValue) {
    if (sValue == null) {
        return null;
    }
    byte[] bytes;
    if (sValue.startsWith(HEX_BEGIN_TOKEN)) {
        String hex = sValue.substring(HEX_BEGIN_TOKEN.length());
        bytes = Hex.decode(hex);
    } else {
        //assume base64 encoded:
        bytes = Base64.decode(sValue);
    }
    return bytes;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:15,代码来源:ReflectionBuilder.java

示例11: toHex

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
/**
 *
 * @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;
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:11,代码来源:AbstractHash.java

示例12: decrypt

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
public String decrypt(String encrypted) {
  try {
    ByteSource decrypted = cipherService.decrypt(Hex.decode(encrypted), getSecretKey());
    return CodecSupport.toString(decrypted.getBytes());
  } catch (CryptoException e) {
    logger.warn(String.format("Someone tried to use an invalid key [%s]", encrypted));
    throw new IllegalArgumentException("Given key is invalid", e);
  }
}
 
开发者ID:obiba,项目名称:mica2,代码行数:10,代码来源:MicaConfigService.java

示例13: getPasword

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
public ByteSource getPasword() {
    if (password != null) {
        return ByteSource.Util.bytes( Hex.decode(password) );
    } else {
        return null;
    }
}
 
开发者ID:UKGovLD,项目名称:registry-core,代码行数:8,代码来源:BaseUserStore.java

示例14: toHex

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
public String toHex() {
    if ( this.cachedHex == null ) {
        this.cachedHex = Hex.encodeToString(getBytes());
    }
    return this.cachedHex;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:7,代码来源:MyByteSource.java

示例15: toHex

import org.apache.shiro.codec.Hex; //导入依赖的package包/类
public String toHex() {
	if (this.cachedHex == null) {
		this.cachedHex = Hex.encodeToString(getBytes());
	}
	return this.cachedHex;
}
 
开发者ID:inexistence,项目名称:VideoMeeting,代码行数:7,代码来源:MySimpleByteSource.java


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