package org.apache.doris.udf.demo;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.lang3.StringUtils;
import java.security.SecureRandom;
/**
* AES encryption and decryption tool class
*
* @author zhangfeng
*/
public class AESUtil {
private static final String defaultCharset = "UTF-8";
private static final String KEY_AES = "AES";
/**
* AES encryption function method
*
* @param content
* @param secret
* @return
*/
public static String encrypt(String content, String secret) {
return doAES(content, secret, Cipher.ENCRYPT_MODE);
}
/**
* AES decryption function method
*
* @param content
* @param secret
* @return
*/
public static String decrypt(String content, String secret) {
return doAES(content, secret, Cipher.DECRYPT_MODE);
}
/**
* encryption and decryption
*
* @param content
* @param secret
* @param mode
* @return
*/
private static String doAES(String content, String secret, int mode) {
try {
if (StringUtils.isBlank(content) || StringUtils.isBlank(secret)) {
return null;
}
//Determine whether to encrypt or decrypt
boolean encrypt = mode == Cipher.ENCRYPT_MODE;
byte[] data;
//1.Construct a key generator, specified as the AES algorithm, case-insensitive
KeyGenerator kgen = KeyGenerator.getInstance(KEY_AES);
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
//2. Initialize the key generator according to the ecnodeRules rules
//Generate a 128-bit random source, based on the incoming byte array
secureRandom.setSeed(secret.getBytes());
//Generate a 128-bit random source, based on the incoming byte array
kgen.init(128, secureRandom);
//3.generate the original symmetric key
SecretKey secretKey = kgen.generateKey();
//4.Get the byte array of the original symmetric key
byte[] enCodeFormat = secretKey.getEncoded();
//5.Generate AES key from byte array
SecretKeySpec keySpec = new SecretKeySpec(enCodeFormat, KEY_AES);
//6.According to the specified algorithm AES self-generated cipher
Cipher cipher = Cipher.getInstance(KEY_AES);
//7.Initialize the cipher, the first parameter is encryption (Encrypt_mode) or decryption (Decrypt_mode) operation,
// the second parameter is the KEY used
cipher.init(mode, keySpec);
if (encrypt) {
data = content.getBytes(defaultCharset);
} else {
data = parseHexStr2Byte(content);
}
byte[] result = cipher.doFinal(data);
if (encrypt) {
//convert binary to hexadecimal
return parseByte2HexStr(result);
} else {
return new String(result, defaultCharset);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return null;
}
/**
* convert binary to hexadecimal
*
* @param buf
* @return
*/
public static String parseByte2HexStr(byte buf[]) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
}
/**
* Convert hexadecimal to binary
*
* @param hexStr
* @return
*/
public static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1) {
return null;
}
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
}
加密函数
package org.apache.doris.udf.demo;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.commons.lang3.StringUtils;
public class AESEncrypt extends UDF {
public String evaluate(String content, String secret) throws Exception {
if (StringUtils.isBlank(content)) {
throw new Exception("content not is null");
}
if (StringUtils.isBlank(secret)) {
throw new Exception("Secret not is null");
}
return AESUtil.encrypt(content, secret);
}
}
解密函数
package org.apache.doris.udf.demo;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.commons.lang3.StringUtils;
public class AESDecrypt extends UDF {
public String evaluate(String content, String secret) throws Exception {
if (StringUtils.isBlank(content)) {
throw new Exception("content not is null");
}
if (StringUtils.isBlank(secret)) {
throw new Exception("Secret not is null");
}
return AESUtil.decrypt(content, secret);
}
}
例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WI
TH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作
在 Service Pack 4 (SP 4), 是运行 Microsoft Windows Server 2003、 Microsoft Windows Storage Server 2003 或 Microsoft Windows 2000 服务器上您尝试安装 Microsoft SQL Server 2000 通过卷许可协议 (VLA) 媒体。 这样做, 收到以下错误信息CD KEY的 SQ
OS 7 has a new method that allows you to draw a view hierarchy into the current graphics context. This can be used to get an UIImage very fast.
I implemented a category method on UIView to get the vi
方法一:
在my.ini的[mysqld]字段加入:
skip-grant-tables
重启mysql服务,这时的mysql不需要密码即可登录数据库
然后进入mysql
mysql>use mysql;
mysql>更新 user set password=password('新密码') WHERE User='root';
mysq
背景
2014年11月12日,ASP.NET之父、微软云计算与企业级产品工程部执行副总裁Scott Guthrie,在Connect全球开发者在线会议上宣布,微软将开源全部.NET核心运行时,并将.NET 扩展为可在 Linux 和 Mac OS 平台上运行。.NET核心运行时将基于MIT开源许可协议发布,其中将包括执行.NET代码所需的一切项目——CLR、JIT编译器、垃圾收集器(GC)和核心