本文整理汇总了Java中org.apache.tomcat.util.codec.binary.Base64.encodeBase64URLSafeString方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.encodeBase64URLSafeString方法的具体用法?Java Base64.encodeBase64URLSafeString怎么用?Java Base64.encodeBase64URLSafeString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.codec.binary.Base64
的用法示例。
在下文中一共展示了Base64.encodeBase64URLSafeString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateSha256
import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
public static String generateSha256(String digestStr) throws Exception{
try{
MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM);
digest.update(digestStr.getBytes());
byte[] hash = digest.digest();
String str = new String(hash);
return Base64.encodeBase64URLSafeString(hash);
}
catch(NoSuchAlgorithmException ex){
throw new Exception(ex.getMessage());
}
}
示例2: encryptRsa
import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
public static String encryptRsa(String digest, Key key){
try {
Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] cipherData = cipher.doFinal(digest.getBytes("UTF-8"));
return Base64.encodeBase64URLSafeString(cipherData);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例3: encryptAes
import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
public static String encryptAes(String digest, String secretKey){
SecretKeySpec aesKey = generateAesKey(secretKey);
try {
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, aesKey);
return Base64.encodeBase64URLSafeString(cipher.doFinal(digest.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例4: generateSha1
import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
public static String generateSha1(String digestStr){
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-1");
digest.update(digestStr.getBytes());
byte[] hash = digest.digest();
return Base64.encodeBase64URLSafeString(hash);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
示例5: generateCryptoString
import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
public static String generateCryptoString(int unencodedLength){
Random cryptoRand = new SecureRandom();
byte[] salt = new byte[unencodedLength];
cryptoRand.nextBytes(salt);
return Base64.encodeBase64URLSafeString(salt);
}
示例6: RsaKeyToString
import org.apache.tomcat.util.codec.binary.Base64; //导入方法依赖的package包/类
public static String RsaKeyToString(Key key){
String result = Base64.encodeBase64URLSafeString(key.getEncoded());
return result;
}