zoukankan      html  css  js  c++  java
  • happy Mom ——php mysqli DES加密

      看完《爱你就像爱生命》这本书,真的看出小波哥很有才,跟小波哥比起来,我唯一拿的出手的可能就是我比他的颜值了。想起一句话,人不是因为美丽而可爱,而是因为可爱而美丽。所以我对我的要求是,继续修炼吧。

      今天被php的mysqli数据库连接和查询,弄的头好头疼。有个查询$conn->query($sql);返回总是false。额,我命名用过这种查询一模一样,那个就好使。看来又被针对了。等解决了放上来。

      (解决了)

    1   $sqlUser = "SELECT id,yonghuming,xingming,jueshe,mima,youxiang,shijian FROM sso_user where id=".$id;  
    2    $resultUser = $conn->prepare($sqlUser);  
    3    $resultUser->execute();
    4    $resultUser->bind_result($id,$yonghuming,$xingming,$jueshe,$mima,$youxiang,$shijian);
    5   // 输出数据  
    7    while($resultUser->fetch()) {  
    8

      分享这个java可加密可解密的程序,亲自用过,不能用默认的jdk,否则有报错。

     1 import java.io.IOException;  
     2 import java.security.SecureRandom;  
     3 import javax.crypto.Cipher;  
     4 import javax.crypto.SecretKey;  
     5 import javax.crypto.SecretKeyFactory;  
     6 import javax.crypto.spec.DESKeySpec;  
     7 import sun.misc.BASE64Decoder;  
     8 import sun.misc.BASE64Encoder;  
     9 public class Des {  
    10   
    11     private byte[] desKey;  
    12   
    13     public Des(String desKey) {  
    14         this.desKey = desKey.getBytes();  
    15     }  
    16   
    17     public byte[] desEncrypt(byte[] plainText) throws Exception {  
    18         SecureRandom sr = new SecureRandom();  
    19         byte rawKeyData[] = desKey;  
    20         DESKeySpec dks = new DESKeySpec(rawKeyData);  
    21         SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");  
    22         SecretKey key = keyFactory.generateSecret(dks);  
    23         Cipher cipher = Cipher.getInstance("DES");  
    24         cipher.init(Cipher.ENCRYPT_MODE, key, sr);  
    25         byte data[] = plainText;  
    26         byte encryptedData[] = cipher.doFinal(data);  
    27         return encryptedData;  
    28     }  
    29   
    30     public byte[] desDecrypt(byte[] encryptText) throws Exception {  
    31         SecureRandom sr = new SecureRandom();  
    32         byte rawKeyData[] = desKey;  
    33         DESKeySpec dks = new DESKeySpec(rawKeyData);  
    34         SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");  
    35         SecretKey key = keyFactory.generateSecret(dks);  
    36         Cipher cipher = Cipher.getInstance("DES");  
    37         cipher.init(Cipher.DECRYPT_MODE, key, sr);  
    38         byte encryptedData[] = encryptText;  
    39         byte decryptedData[] = cipher.doFinal(encryptedData);  
    40         return decryptedData;  
    41     }  
    42   
    43     public String encrypt(String input) throws Exception {  
    44         return base64Encode(desEncrypt(input.getBytes()));  
    45     }  
    46   
    47     public String decrypt(String input) throws Exception {  
    48         byte[] result = base64Decode(input);  
    49         return new String(desDecrypt(result));  
    50     }  
    51   
    52     public static String base64Encode(byte[] s) {  
    53         if (s == null)  
    54             return null;  
    55         BASE64Encoder b = new sun.misc.BASE64Encoder();  
    56         return b.encode(s);  
    57     }  
    58   
    59     public static byte[] base64Decode(String s) throws IOException {  
    60         if (s == null)  
    61             return null;  
    62         BASE64Decoder decoder = new BASE64Decoder();  
    63         byte[] b = decoder.decodeBuffer(s);  
    64         return b;  
    65     }  
    66   
    67     public static void main(String[] args) throws Exception {  
    68         String key = "abcdefgh";  
    69         String input = "a";  
    70         Des crypt = new Des(key);  
    71         System.out.println("Encode:" + crypt.encrypt(input));  
    72         System.out.println("Decode:" + crypt.decrypt(crypt.encrypt(input)));  
    73     }  
    74 }  

      今天是妈妈的生日,我很感谢她树立了我的三观,希望她能在今后的每一天都过得开心,过得幸福。

      所以今天冰心的《写给母亲的诗》送给她

      母亲,好久以来

      就想为你写一首诗

      但写了好多次

      还是没有写好

      母亲,为你写的这首诗

      我不知道该怎样开头

      不知道该怎样结尾

      也不知道该写些什么

      就像儿时面对你严厉的巴掌

      我不知道是该勇敢接受

      还是该选择逃避

      母亲,今夜我又想起了你

      我决定还是要为你写一首诗

      哪怕写得不好

      哪怕远在老家的你

      永远也读不到……

      母亲,

      倘若你梦中看见一只很小的白船儿,

      不要惊讶他无端入梦。

      这是你至爱的女儿(儿子左)含着泪叠的,

      万水千山,

      求他载着她的爱和悲哀归去。

      

  • 相关阅读:
    apple ID的重要性
    使用spring实现邮件的发送(含测试,源码,注释)
    使用java底层实现邮件的发送(含测试,源码)
    使用java底层实现邮件的发送(含测试,源码)
    java实现邮件发送准备工作(前期配置)
    java实现邮件发送准备工作(前期配置)
    Java实现最电话号码的简单加密源码
    Java实现最电话号码的简单加密源码
    java实现加密电话号码,有具体的加密流程注释
    java实现加密电话号码,有具体的加密流程注释
  • 原文地址:https://www.cnblogs.com/zzuuoo666/p/7464516.html
Copyright © 2011-2022 走看看