java aes GetAlgorithProvider and UnicodeChinese

3892 단어
package com.jiepu;

import java.security.Provider.Service;
import java.security.Provider;
import java.security.Security;
import java.util.Set;


public class GetAlgorithProvider {

	public static void main(String[] args) {
		
		
		Provider[] provider=Security.getProviders();

		for (Provider provider2 : provider) {
			//String json=JSON.toJSONString(provider2);
			Set<Service> set=provider2.getServices();
			//System.out.println(set);
			for (Service service : set) {
				//System.out.println(service.getType()+","+service.getAlgorithm());
				System.out.println(service.getAlgorithm());
				
			}
		}
	}
}
package com.jiepu;

public class UnicodeChinese{


	public static String decodeUnicode(String theString) {
		char aChar;
		int len = theString.length();
		StringBuffer outBuffer = new StringBuffer(len);
		for (int x = 0; x < len;) {
			aChar = theString.charAt(x++);
			if (aChar == '\\') {
				aChar = theString.charAt(x++);
				if (aChar == 'u') {
					// Read the xxxx
					int value = 0;
					for (int i = 0; i < 4; i++) {
						aChar = theString.charAt(x++);
						switch (aChar) {
						case '0':
						case '1':
						case '2':
						case '3':
						case '4':
						case '5':
						case '6':
						case '7':
						case '8':
						case '9':
							value = (value << 4) + aChar - '0';
							break;
						case 'a':
						case 'b':
						case 'c':
						case 'd':
						case 'e':
						case 'f':
							value = (value << 4) + 10 + aChar - 'a';
							break;
						case 'A':
						case 'B':
						case 'C':
						case 'D':
						case 'E':
						case 'F':
							value = (value << 4) + 10 + aChar - 'A';
							break;
						default:
							throw new IllegalArgumentException(
									"Malformed   \\uxxxx   encoding.");
						}

					}
					outBuffer.append((char) value);
				} else {
					if (aChar == 't')
						aChar = '\t';
					else if (aChar == 'r')
						aChar = '\r';
					else if (aChar == 'n')
						aChar = '
'; else if (aChar == 'f') aChar = '\f'; outBuffer.append(aChar); } } else outBuffer.append(aChar); } return outBuffer.toString(); } /** * unicode * * @param str * @return unicode */ public static String chineseToUnicode(String str) { StringBuffer result = new StringBuffer(); for (int i = 0; i < str.length(); i++) { result.append("\\u" + Integer.toHexString(str.charAt(i))); } return result.toString(); } /** * unicode * * @param str * @return */ public static String unicodeToChinese(String str) { StringBuffer sb = new StringBuffer(); for(char ch:str.toCharArray()) sb.append(ch); //sb.append(str.toCharArray()); return sb.toString(); } public static void main(String args[]) { // unicode �? String str = "\u767b\u5f55\u793e\u533a"; System.out.println(unicodeToChinese(str)); for (char c : str.toCharArray()) System.out.print(c); System.out.println(); String result =chineseToUnicode(" "); System.out.println(result); System.out.println(chineseToUnicode(" 2 ")); String hehe="\u7b2c2\u671f\u5168\u6c11\u6709\u5956\u7b54\u9898\u7efc\u827a\u771f\u4eba\u79c0\u5b8c\u7f8e\u843d\u5e55"; str = unicodeToChinese("\u7b2c2\u671f\u5168\u6c11\u6709\u5956\u7b54\u9898\u7efc\u827a\u771f\u4eba\u79c0\u5b8c\u7f8e\u843d\u5e55"); System.out.println(str); System.out.println(decodeUnicode(hehe)); } }
http://www.cnitblog.com/neatstudio/archive/2006/07/28/14315.html

좋은 웹페이지 즐겨찾기