须要用到一个jar

http://www.bouncycastle.org/latest_releases.html

须要注意的问题

JS用同一秘钥生成的密文用java解密出来是逆序的,即js加密123456用java解密出来是654321,原因未知,须要解密js加密的密文请使用后缀为byJs的方法。

HexUtil.java

  1. > 1];
  2.  
  3. // two characters form the hex value.
  4. for (int i = 0, j = 0; j >> 4];
  5. out[j++] = toDigits[0x0F & data[i]];
  6. }
  7. return out;
  8. }
  9. }
  10. " data-snippet-id="ext.95f10f39d6786f444dfe7f63f74db7ec" data-snippet-saved="false" data-csrftoken="ccbrPHwP-WyjtuyjuHUnUI5J2rTNMwFME_ks" data-codota-status="done">package cn.edu.zafu.utils;
  11. public class HexUtil {
  12. private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5',
  13. '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
  14. private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5',
  15. '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
  16. public static byte[] decodeHex(final char[] data) throws Exception {
  17. final int len = data.length;
  18. if ((len & 0x01) != 0) {
  19. throw new Exception("Odd number of characters.");
  20. }
  21. final byte[] out = new byte[len >> 1];
  22. // two characters form the hex value.
  23. for (int i = 0, j = 0; j < len; i++) {
  24. int f = toDigit(data[j], j) << 4;
  25. j++;
  26. f = f | toDigit(data[j], j);
  27. j++;
  28. out[i] = (byte) (f & 0xFF);
  29. }
  30. return out;
  31. }
  32. protected static int toDigit(final char ch, final int index)
  33. throws Exception {
  34. final int digit = Character.digit(ch, 16);
  35. if (digit == -1) {
  36. throw new Exception("Illegal hexadecimal character " + ch
  37. + " at index " + index);
  38. }
  39. return digit;
  40. }
  41. public static char[] encodeHex(final byte[] data) {
  42. return encodeHex(data, true);
  43. }
  44. public static char[] encodeHex(final byte[] data, final boolean toLowerCase) {
  45. return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
  46. }
  47. protected static char[] encodeHex(final byte[] data, final char[] toDigits) {
  48. final int l = data.length;
  49. final char[] out = new char[l << 1];
  50. // two characters form the hex value.
  51. for (int i = 0, j = 0; i < l; i++) {
  52. out[j++] = toDigits[(0xF0 & data[i]) >>> 4];
  53. out[j++] = toDigits[0x0F & data[i]];
  54. }
  55. return out;
  56. }
  57. }

StringUtil.java

  1. package cn.edu.zafu.utils;
  2. public class StringUtil {
  3. public static boolean isBlank(final CharSequence cs) {
  4. int strLen;
  5. if (cs == null || (strLen = cs.length()) == 0) {
  6. return true;
  7. }
  8. for (int i = 0; i < strLen; i++) {
  9. if (Character.isWhitespace(cs.charAt(i)) == false) {
  10. return false;
  11. }
  12. }
  13. return true;
  14. }
  15. public static String reverse(final String str) {
  16. if (str == null) {
  17. return null;
  18. }
  19. return new StringBuilder(str).reverse().toString();
  20. }
  21. }

FileUtil.java

  1. package cn.edu.zafu.utils;
  2. import java.io.Closeable;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. public class FileUtils {
  10. public static FileInputStream openInputStream(File file) throws IOException {
  11. if (file.exists()) {
  12. if (file.isDirectory()) {
  13. throw new IOException("File '" + file
  14. + "' exists but is a directory");
  15. }
  16. if (file.canRead() == false) {
  17. throw new IOException("File '" + file + "' cannot be read");
  18. }
  19. } else {
  20. throw new FileNotFoundException("File '" + file
  21. + "' does not exist");
  22. }
  23. return new FileInputStream(file);
  24. }
  25. public static FileOutputStream openOutputStream(File file)
  26. throws IOException {
  27. return openOutputStream(file, false);
  28. }
  29. public static FileOutputStream openOutputStream(File file, boolean append)
  30. throws IOException {
  31. if (file.exists()) {
  32. if (file.isDirectory()) {
  33. throw new IOException("File '" + file
  34. + "' exists but is a directory");
  35. }
  36. if (file.canWrite() == false) {
  37. throw new IOException("File '" + file
  38. + "' cannot be written to");
  39. }
  40. } else {
  41. File parent = file.getParentFile();
  42. if (parent != null) {
  43. if (!parent.mkdirs() && !parent.isDirectory()) {
  44. throw new IOException("Directory '" + parent
  45. + "' could not be created");
  46. }
  47. }
  48. }
  49. return new FileOutputStream(file, append);
  50. }
  51. public static void closeQuietly(InputStream input) {
  52. closeQuietly((Closeable) input);
  53. }
  54. public static void closeQuietly(Closeable closeable) {
  55. try {
  56. if (closeable != null) {
  57. closeable.close();
  58. }
  59. } catch (IOException ioe) {
  60. // ignore
  61. }
  62. }
  63. }

RSAUtil.java

  1. package cn.edu.zafu.utils;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.ObjectInputStream;
  6. import java.io.ObjectOutputStream;
  7. import java.math.BigInteger;
  8. import java.security.KeyPair;
  9. import java.security.KeyFactory;
  10. import java.security.KeyPairGenerator;
  11. import java.security.Provider;
  12. import java.security.PublicKey;
  13. import java.security.PrivateKey;
  14. import java.security.SecureRandom;
  15. import java.security.NoSuchAlgorithmException;
  16. import java.security.InvalidParameterException;
  17. import java.security.interfaces.RSAPublicKey;
  18. import java.security.interfaces.RSAPrivateKey;
  19. import java.security.spec.RSAPublicKeySpec;
  20. import java.text.SimpleDateFormat;
  21. import java.util.Date;
  22. import java.security.spec.RSAPrivateKeySpec;
  23. import java.security.spec.InvalidKeySpecException;
  24. import javax.crypto.Cipher;
  25. import org.bouncycastle.jce.provider.BouncyCastleProvider;
  26. /**
  27. * RSA算法加密/解密工具类。
  28. *
  29. *
  30. */
  31. public abstract class RSAUtil {
  32. /** 算法名称 */
  33. private static final String ALGORITHOM = "RSA";
  34. /**保存生成的密钥对的文件名。 */
  35. private static final String RSA_PAIR_FILENAME = "/__RSA_PAIR.txt";
  36. /** 密钥大小 */
  37. private static final int KEY_SIZE = 1024;
  38. /** 默认的安全服务提供者 */
  39. private static final Provider DEFAULT_PROVIDER = new BouncyCastleProvider();
  40. private static KeyPairGenerator keyPairGen = null;
  41. private static KeyFactory keyFactory = null;
  42. /** 缓存的密钥对。 */
  43. private static KeyPair oneKeyPair = null;
  44. private static File rsaPairFile = null;
  45. static {
  46. try {
  47. keyPairGen = KeyPairGenerator.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
  48. keyFactory = KeyFactory.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
  49. } catch (NoSuchAlgorithmException ex) {
  50. System.out.println(ex.getMessage());
  51. }
  52. rsaPairFile = new File(getRSAPairFilePath());
  53. }
  54. private RSAUtil() {
  55. }
  56. /**
  57. * 生成并返回RSA密钥对。
  58. */
  59. private static synchronized KeyPair generateKeyPair() {
  60. try {
  61. keyPairGen.initialize(KEY_SIZE, new SecureRandom(new SimpleDateFormat("yyyyMMdd").format(new Date()).getBytes()));
  62. oneKeyPair = keyPairGen.generateKeyPair();
  63. saveKeyPair(oneKeyPair);
  64. return oneKeyPair;
  65. } catch (InvalidParameterException ex) {
  66. System.out.println("KeyPairGenerator does not support a key length of " + KEY_SIZE + ".");
  67. ex.printStackTrace();
  68. } catch (NullPointerException ex) {
  69. System.out.println("RSAUtils#KEY_PAIR_GEN is null, can not generate KeyPairGenerator instance.");
  70. ex.printStackTrace();
  71. }
  72. return null;
  73. }
  74. /**
  75. * 返回生成/读取的密钥对文件的路径。
  76. */
  77. private static String getRSAPairFilePath() {
  78. String urlPath = RSAUtil.class.getResource("/").getPath();
  79. return (new File(urlPath).getParent() + RSA_PAIR_FILENAME);
  80. }
  81. /**
  82. * 若须要创建新的密钥对文件,则返回 {@code true}。否则 {@code false}。
  83. */
  84. private static boolean isCreateKeyPairFile() {
  85. // 是否创建新的密钥对文件
  86. boolean createNewKeyPair = false;
  87. if (!rsaPairFile.exists() || rsaPairFile.isDirectory()) {
  88. createNewKeyPair = true;
  89. }
  90. return createNewKeyPair;
  91. }
  92. /**
  93. * 将指定的RSA密钥对以文件形式保存。
  94. *
  95. * @param keyPair 要保存的密钥对。
  96. */
  97. private static void saveKeyPair(KeyPair keyPair) {
  98. FileOutputStream fos = null;
  99. ObjectOutputStream oos = null;
  100. try {
  101. fos = FileUtils.openOutputStream(rsaPairFile);
  102. oos = new ObjectOutputStream(fos);
  103. oos.writeObject(keyPair);
  104. } catch (Exception ex) {
  105. ex.printStackTrace();
  106. } finally {
  107. FileUtils.closeQuietly(oos);
  108. FileUtils.closeQuietly(fos);
  109. }
  110. }
  111. /**
  112. * 返回RSA密钥对。
  113. */
  114. public static KeyPair getKeyPair() {
  115. // 首先推断是否须要又一次生成新的密钥对文件
  116. if (isCreateKeyPairFile()) {
  117. // 直接强制生成密钥对文件,并存入缓存。
  118. return generateKeyPair();
  119. }
  120. if (oneKeyPair != null) {
  121. return oneKeyPair;
  122. }
  123. return readKeyPair();
  124. }
  125. // 同步读出保存的密钥对
  126. private static KeyPair readKeyPair() {
  127. FileInputStream fis = null;
  128. ObjectInputStream ois = null;
  129. try {
  130. fis = FileUtils.openInputStream(rsaPairFile);
  131. ois = new ObjectInputStream(fis);
  132. oneKeyPair = (KeyPair) ois.readObject();
  133. return oneKeyPair;
  134. } catch (Exception ex) {
  135. ex.printStackTrace();
  136. } finally {
  137. FileUtils.closeQuietly(ois);
  138. FileUtils.closeQuietly(fis);
  139. }
  140. return null;
  141. }
  142. /**
  143. * 依据给定的系数和专用指数构造一个RSA专用的公钥对象。
  144. *
  145. * @param modulus 系数。
  146. * @param publicExponent 专用指数。
  147. * @return RSA专用公钥对象。
  148. */
  149. public static RSAPublicKey generateRSAPublicKey(byte[] modulus, byte[] publicExponent) {
  150. RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(new BigInteger(modulus),
  151. new BigInteger(publicExponent));
  152. try {
  153. return (RSAPublicKey) keyFactory.generatePublic(publicKeySpec);
  154. } catch (InvalidKeySpecException ex) {
  155. System.out.println("RSAPublicKeySpec is unavailable.");
  156. ex.printStackTrace();
  157. } catch (NullPointerException ex) {
  158. System.out.println("RSAUtils#KEY_FACTORY is null, can not generate KeyFactory instance.");
  159. ex.printStackTrace();
  160. }
  161. return null;
  162. }
  163. /**
  164. * 依据给定的系数和专用指数构造一个RSA专用的私钥对象。
  165. *
  166. * @param modulus 系数。
  167. * @param privateExponent 专用指数。
  168. * @return RSA专用私钥对象。
  169. */
  170. public static RSAPrivateKey generateRSAPrivateKey(byte[] modulus, byte[] privateExponent) {
  171. RSAPrivateKeySpec privateKeySpec = new RSAPrivateKeySpec(new BigInteger(modulus),
  172. new BigInteger(privateExponent));
  173. try {
  174. return (RSAPrivateKey) keyFactory.generatePrivate(privateKeySpec);
  175. } catch (InvalidKeySpecException ex) {
  176. System.out.println("RSAPrivateKeySpec is unavailable.");
  177. ex.printStackTrace();
  178. } catch (NullPointerException ex) {
  179. System.out.println("RSAUtils#KEY_FACTORY is null, can not generate KeyFactory instance.");
  180. ex.printStackTrace();
  181. }
  182. return null;
  183. }
  184. /**
  185. * 依据给定的16进制系数和专用指数字符串构造一个RSA专用的私钥对象。
  186. *
  187. * @param modulus 系数。
  188. * @param privateExponent 专用指数。
  189. * @return RSA专用私钥对象。
  190. */
  191. public static RSAPrivateKey getRSAPrivateKey(String hexModulus, String hexPrivateExponent) {
  192. if(StringUtil.isBlank(hexModulus) || StringUtil.isBlank(hexPrivateExponent)) {
  193. System.out.println("hexModulus and hexPrivateExponent cannot be empty. RSAPrivateKey value is null to return.");
  194. return null;
  195. }
  196. byte[] modulus = null;
  197. byte[] privateExponent = null;
  198. try {
  199. modulus = HexUtil.decodeHex(hexModulus.toCharArray());
  200. privateExponent = HexUtil.decodeHex(hexPrivateExponent.toCharArray());
  201. } catch(Exception ex) {
  202. System.out.println("hexModulus or hexPrivateExponent value is invalid. return null(RSAPrivateKey).");
  203. ex.printStackTrace();
  204. }
  205. if(modulus != null && privateExponent != null) {
  206. return generateRSAPrivateKey(modulus, privateExponent);
  207. }
  208. return null;
  209. }
  210. /**
  211. * 依据给定的16进制系数和专用指数字符串构造一个RSA专用的公钥对象。
  212. *
  213. * @param modulus 系数。
  214. * @param publicExponent 专用指数。
  215. * @return RSA专用公钥对象。
  216. */
  217. public static RSAPublicKey getRSAPublicKey(String hexModulus, String hexPublicExponent) {
  218. if(StringUtil.isBlank(hexModulus) || StringUtil.isBlank(hexPublicExponent)) {
  219. System.out.println("hexModulus and hexPublicExponent cannot be empty. return null(RSAPublicKey).");
  220. return null;
  221. }
  222. byte[] modulus = null;
  223. byte[] publicExponent = null;
  224. try {
  225. modulus = HexUtil.decodeHex(hexModulus.toCharArray());
  226. publicExponent = HexUtil.decodeHex(hexPublicExponent.toCharArray());
  227. } catch(Exception ex) {
  228. System.out.println("hexModulus or hexPublicExponent value is invalid. return null(RSAPublicKey).");
  229. ex.printStackTrace();
  230. }
  231. if(modulus != null && publicExponent != null) {
  232. return generateRSAPublicKey(modulus, publicExponent);
  233. }
  234. return null;
  235. }
  236. /**
  237. * 使用指定的公钥加密数据。
  238. *
  239. * @param publicKey 给定的公钥。
  240. * @param data 要加密的数据。
  241. * @return 加密后的数据。
  242. */
  243. public static byte[] encrypt(PublicKey publicKey, byte[] data) throws Exception {
  244. Cipher ci = Cipher.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
  245. ci.init(Cipher.ENCRYPT_MODE, publicKey);
  246. return ci.doFinal(data);
  247. }
  248. /**
  249. * 使用指定的私钥解密数据。
  250. *
  251. * @param privateKey 给定的私钥。
  252. * @param data 要解密的数据。
  253. * @return 原数据。
  254. */
  255. public static byte[] decrypt(PrivateKey privateKey, byte[] data) throws Exception {
  256. Cipher ci = Cipher.getInstance(ALGORITHOM, DEFAULT_PROVIDER);
  257. ci.init(Cipher.DECRYPT_MODE, privateKey);
  258. return ci.doFinal(data);
  259. }
  260. /**
  261. * 使用给定的公钥加密给定的字符串。
  262. * <p />
  263. * 若 {@code publicKey} 为 {@code null}。或者 {@code plaintext} 为 {@code null} 则返回 {@code
  264. * null}。
  265. *
  266. * @param publicKey 给定的公钥。
  267. * @param plaintext 字符串。
  268. * @return 给定字符串的密文。
  269. */
  270. public static String encryptString(PublicKey publicKey, String plaintext) {
  271. if (publicKey == null || plaintext == null) {
  272. return null;
  273. }
  274. byte[] data = plaintext.getBytes();
  275. try {
  276. byte[] en_data = encrypt(publicKey, data);
  277. return new String(HexUtil.encodeHex(en_data));
  278. } catch (Exception ex) {
  279. ex.printStackTrace();
  280. }
  281. return null;
  282. }
  283. /**
  284. * 使用默认的公钥加密给定的字符串。
  285. * <p />
  286. * 若{@code plaintext} 为 {@code null} 则返回 {@code null}。
  287. *
  288. * @param plaintext 字符串。
  289. * @return 给定字符串的密文。
  290. */
  291. public static String encryptString(String plaintext) {
  292. if(plaintext == null) {
  293. return null;
  294. }
  295. byte[] data = plaintext.getBytes();
  296. KeyPair keyPair = getKeyPair();
  297. try {
  298. byte[] en_data = encrypt((RSAPublicKey)keyPair.getPublic(), data);
  299. return new String(HexUtil.encodeHex(en_data));
  300. } catch(NullPointerException ex) {
  301. System.out.println("keyPair cannot be null.");
  302. ex.printStackTrace();
  303. } catch(Exception ex) {
  304. ex.printStackTrace();
  305. }
  306. return null;
  307. }
  308. /**
  309. * 生成由JS的RSA加密的字符串。
  310. * @param publicKey 公钥
  311. * @param plaintext 原文字符串
  312. * @return 加密后的字符串
  313. */
  314. public static String encryptStringByJs(PublicKey publicKey, String plaintext) {
  315. if(plaintext == null) {
  316. return null;
  317. }
  318. String text = encryptString(publicKey,StringUtil.reverse(plaintext));
  319. return text;
  320. }
  321. /**
  322. * 用默认公钥生成由JS的RSA加密的字符串。
  323. * @param publicKey 公钥
  324. * @param plaintext 原文字符串
  325. * @return 加密后的字符串
  326. */
  327. public static String encryptStringByJs( String plaintext) {
  328. if(plaintext == null) {
  329. return null;
  330. }
  331. String text = encryptString(StringUtil.reverse(plaintext));
  332. return text;
  333. }
  334. /**
  335. * 使用给定的私钥解密给定的字符串。
  336. * <p />
  337. * 若私钥为 {@code null},或者 {@code encrypttext} 为 {@code null}或空字符串则返回 {@code null}。
  338. * 私钥不匹配时,返回 {@code null}。
  339. *
  340. * @param privateKey 给定的私钥。
  341. * @param encrypttext 密文。
  342. * @return 原文字符串。
  343. */
  344. public static String decryptString(PrivateKey privateKey, String encrypttext) {
  345. if (privateKey == null || StringUtil.isBlank(encrypttext)) {
  346. return null;
  347. }
  348. try {
  349. byte[] en_data =HexUtil.decodeHex(encrypttext.toCharArray());
  350. byte[] data = decrypt(privateKey, en_data);
  351. return new String(data);
  352. } catch (Exception ex) {
  353. System.out.println(String.format("\"%s\" Decryption failed. Cause: %s", encrypttext, ex.getCause().getMessage()));
  354. }
  355. return null;
  356. }
  357. /**
  358. * 使用默认的私钥解密给定的字符串。
  359. * <p />
  360. * 若{@code encrypttext} 为 {@code null}或空字符串则返回 {@code null}。
  361. * 私钥不匹配时,返回 {@code null}。
  362. *
  363. * @param encrypttext 密文。
  364. * @return 原文字符串。
  365. */
  366. public static String decryptString(String encrypttext) {
  367. if(StringUtil.isBlank(encrypttext)) {
  368. return null;
  369. }
  370. KeyPair keyPair = getKeyPair();
  371. try {
  372. byte[] en_data = HexUtil.decodeHex(encrypttext.toCharArray());
  373. byte[] data = decrypt((RSAPrivateKey)keyPair.getPrivate(), en_data);
  374. return new String(data);
  375. } catch(NullPointerException ex) {
  376. System.out.println("keyPair cannot be null.");
  377. ex.printStackTrace();
  378. } catch (Exception ex) {
  379. System.out.println(String.format("\"%s\" Decryption failed. Cause: %s", encrypttext, ex.getMessage()));
  380. ex.printStackTrace();
  381. }
  382. return null;
  383. }
  384. /**
  385. * 使用指定的私钥解密由JS加密的字符串。
  386. * @param privateKey 私钥
  387. * @param encrypttext 密文
  388. * @return {@code encrypttext} 的原文字符串
  389. */
  390. public static String decryptStringByJs(PrivateKey privateKey,String encrypttext) {
  391. String text = decryptString(privateKey,encrypttext);
  392. if(text == null) {
  393. return null;
  394. }
  395. return StringUtil.reverse(text);
  396. }
  397. /**
  398. * 使用默认的私钥解密由JS加密(使用此类提供的公钥加密)的字符串。
  399. *
  400. * @param encrypttext 密文。
  401. * @return {@code encrypttext} 的原文字符串。
  402. */
  403. public static String decryptStringByJs(String encrypttext) {
  404. String text = decryptString(encrypttext);
  405. if(text == null) {
  406. return null;
  407. }
  408. return StringUtil.reverse(text);
  409. }
  410. /** 返回已初始化的默认的公钥。
  411. */
  412. public static RSAPublicKey getDefaultPublicKey() {
  413. KeyPair keyPair = getKeyPair();
  414. if(keyPair != null) {
  415. return (RSAPublicKey)keyPair.getPublic();
  416. }
  417. return null;
  418. }
  419. /** 返回已初始化的默认的私钥。*/
  420. public static RSAPrivateKey getDefaultPrivateKey() {
  421. KeyPair keyPair = getKeyPair();
  422. if(keyPair != null) {
  423. return (RSAPrivateKey)keyPair.getPrivate();
  424. }
  425. return null;
  426. }
  427. }

源代码下载

http://download.csdn.net/detail/sbsujjbcy/8897029

JAVA的RSA加密算法工具类的更多相关文章

  1. Rhino+envjs-1.2.js 在java运行网站js 工具类

    java爬虫遇到个页面加密的东西,找了些资料学习学习 做了个java运行js的工具类,希望对大家有用,其中用到client(获取js)可以自行换成自己的client.主要是用了 Rhino就是Java ...

  2. java中常用的工具类(一)

    我们java程序员在开发项目的是常常会用到一些工具类.今天我汇总了一下java中常用的工具方法.大家可以在项目中使用.可以收藏!加入IT江湖官方群:383126909 我们一起成长 一.String工 ...

  3. Java学习-041-颜色工具类(RGB,HEX)

    在日常的网页开发中,经常需要进行颜色数值获取.转换,例如获取红色,获取蓝色,获取绿色,RGB转十六进制颜色,十六进制颜色转RGB等,因而在学习过程中,写了一个小工具类,仅供各位小主参考! 多不闲言,直 ...

  4. JAVA中封装JSONUtils工具类及使用

    在JAVA中用json-lib-2.3-jdk15.jar包中提供了JSONObject和JSONArray基类,用于JSON的序列化和反序列化的操作.但是我们更习惯将其进一步封装,达到更好的重用. ...

  5. JAVA自动生成正则表达式工具类

    经过很久的努力,终于完成了JAVA自动生成正则表达式工具类.还记得之前需要正则,老是从网上找吗?找了想修改也不会修改.现在不用再为此烦恼了,使用此生成类轻松搞定所有正则表达式.赶快在同事面前炫一下吧. ...

  6. java 二进制数字符串转换工具类

    java 二进制数字符串转换工具类 将二进制转换成八进制 将二进制转换成十进制 将二进制转换成十六进制 将十进制转换成二进制 package com.iteye.injavawetrust.ad; i ...

  7. Java学习-049-正则工具类

    自去年九月份决定再次入学和职业资格进阶,开始备战二者考试至今,以及当下进行中的职称申请,犹如孤独的狼,不断前行在路上,而今凡凡总总的已历8月... 不感慨了,如下为一园友需要的正则工具类,直接上码: ...

  8. Java 后台验证的工具类

    Java 后台验证的工具类 public class ValidationUtil {         //手机号     public static String mobile = "^( ...

  9. java后端时间处理工具类,返回 "XXX 前" 的字符串

    转自:https://www.cnblogs.com/devise/p/9974672.html 我们经常会遇到显示 "某个之间之前" 的需求(比如各种社交软件,在回复消息时,显示 ...

随机推荐

  1. jQuery回到顶部

    jquery回到顶部 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset=& ...

  2. DedeCMS批量替换栏目文件保存目录的方法

    学点sql还是很有必要的.   有时候由于栏目太多,但是要修改一下栏目的保存目录.一个一个修改真的有点费事和慢.所以想了一个方法来批量修改栏目的保存目录.就是批量替换: update dede_arc ...

  3. Nginx环境下常见的开源项目重写汇总

    我们做PHP开发的,作者寒冰我觉得大部分时候都在跟开源的系统打交道.比如:Discuz.PHPCMS.ecshop.wordpress等开源系统.一般我们都是在本地搭建测试环境,用的web服务器都是a ...

  4. TreeView 数据绑定及选中命令处理

    昨天接近下班,一个群里面的网友,问treeView绑定后  选中命令怎么来处理,怎么没有效果,而且用MVVM的方式来写:快下班了本来想远程帮他看下,结果就说写个Demo给他看:再加上选中传参: 下面分 ...

  5. 东软实训1 -jsp内置对象及其常用方法

    JSP 的内置对象及方法详细说明 一. request 对象 客户端的请求信息被封装在 request 对象中,通过它才能了解到客户的需 求,然后做出响应.它是 HttpServletRequest ...

  6. PHP学习系列(1)——字符串处理函数(3)

    11.crc32() 函数计算一个字符串的 crc32 多项式.生成 string 参数的 32 位循环冗余校验码多项式.该函数可用于验证数据的完整性. 语法:crc32(string) 注意:由于 ...

  7. Python自动化运维之2、运算符与数据类型

    python对象的相关术语: python程序中保存的所有数据都是围绕对象这个概念展开的: 程序中存储的所有数据都是对象 每个对象都有一个身份.一个类型和一个值 例如,school='MaGe Lin ...

  8. Objective C内存管理之理解autorelease------面试题

    Objective C内存管理之理解autorelease   Autorelease实际上只是把对release的调用延迟了,对于每一个Autorelease,系统只是把该Object放入了当前的A ...

  9. DbUtility-查询DataTable

    直接上源码 using System; using System.Data; using System.Threading.Tasks; using DbUtility; namespace Test ...

  10. 浅析Android中的消息机制

    在分析Android消息机制之前,我们先来看一段代码: public class MainActivity extends Activity implements View.OnClickListen ...