汉字姓名生成unicode码的简单算法

public class UnicodeConverter {
	public static void main(String[] args) {
		String name="黄云增";
		String unicodeName="";
		for(int i=0;i<name.length();i++){
			if((int)name.charAt(i)<256){
				unicodeName+="\\u00"+Integer.toHexString(name.charAt(i));
			}else{
				unicodeName+="\\u"+Integer.toHexString(name.charAt(i));
			}
		}
		System.out.println(unicodeName);
	}
}

 

好的,根据您的要求,我可以提供一个示例代来使用您的姓名汉字UNICODE编码作为密钥进行加解密。以下是示例代: ```java import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.util.Arrays; public class UnicodeKeyAES { private static final int KEY_SIZE = 16; // 128位密钥 private static final String ALGORITHM = "AES"; public static void main(String[] args) { String name = "张三"; // 您的姓名,用Unicode编码后作为密钥 byte[] key = extendKey(name.getBytes(StandardCharsets.UTF_8)); byte[] plaintext = "Hello, world!".getBytes(StandardCharsets.UTF_8); byte[] ciphertext = encrypt(key, plaintext); byte[] decryptedtext = decrypt(key, ciphertext); System.out.println("Plaintext: " + new String(plaintext, StandardCharsets.UTF_8)); System.out.println("Ciphertext: " + Arrays.toString(ciphertext)); System.out.println("Decryptedtext: " + new String(decryptedtext, StandardCharsets.UTF_8)); } private static byte[] extendKey(byte[] key) { byte[] extendedKey = new byte[KEY_SIZE]; for (int i = 0; i < KEY_SIZE; i++) { if (i < key.length) { extendedKey[i] = key[i]; } else { extendedKey[i] = 0; // 不足的位数用0填充 } } return extendedKey; } private static byte[] encrypt(byte[] key, byte[] plaintext) { try { SecretKeySpec secretKey = new SecretKeySpec(key, ALGORITHM); Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.ENCRYPT_MODE, secretKey); return cipher.doFinal(plaintext); } catch (Exception e) { e.printStackTrace(); return null; } } private static byte[] decrypt(byte[] key, byte[] ciphertext) { try { SecretKeySpec secretKey = new SecretKeySpec(key, ALGORITHM); Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, secretKey); return cipher.doFinal(ciphertext); } catch (Exception e) { e.printStackTrace(); return null; } } } ``` 在这个示例代中,我们使用了您的姓名“张三”作为密钥,将其用UTF-8编码转换为字节数组,并将其扩展为128位(16字节)的密钥。然后,我们使用AES算法对明文“Hello, world!”进行加密,并输出密文和解密后的明文。 请注意,虽然使用自己的姓名作为密钥可能不够安全,但这只是一个示例,真正的应用中应该使用更为安全的密钥生成方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值