久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 3078|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

基于RSA和LSB的圖像隱藏技術(shù) 附Java源程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
一、項(xiàng)目背景
隨著Internet技術(shù)和多媒體信息技術(shù)的飛速發(fā)展,多媒體、計(jì)算機(jī)網(wǎng)絡(luò)、個(gè)人移動(dòng)通信技術(shù)等進(jìn)入尋常百姓家,數(shù)字化已深入人心。數(shù)字多媒體信息在網(wǎng)上傳播與傳輸越來(lái)越方便,通過(guò)網(wǎng)絡(luò)傳遞各種信息越來(lái)越普遍。但與此同時(shí)也帶來(lái)了信息安全的隱患問(wèn)題。信息隱藏是近年來(lái)信息安全和多媒體信號(hào)處理領(lǐng)域中提出的一種解決媒體信息安全的新方法。它通過(guò)把秘密信息隱藏在可公開(kāi)的媒體信息里,達(dá)到證實(shí)該媒體信息的數(shù)據(jù)完整性或傳遞秘密信息的目的,從而為數(shù)字信息的安全問(wèn)題提供了一種新的解決方法。
二、軟件原理及內(nèi)容
1、原理
LSB(LeastSignificantBits)算法:將秘密信息嵌入到載體圖像像素值的最低有效位,也稱最不顯著位,改變這一位置對(duì)載體圖像的品質(zhì)影響最小。
LSB算法基本原理:對(duì)空域的LSB做替換,用來(lái)替換LSB的序列就是需要加入的水印信息、水印的數(shù)字摘要或者由水印生成的偽隨機(jī)序列。由于水印信息嵌入的位置是LSB,為了滿足水印的不可見(jiàn)性,允許嵌入的水印強(qiáng)度不可能太高。然而針對(duì)空域的各種處理,如游程編碼前的預(yù)處理,會(huì)對(duì)不顯著分量進(jìn)行一定的壓縮,所以LSB算法對(duì)這些操作很敏感。因此LSB算法最初是用于脆弱性水印的。
2、內(nèi)容
(1)編寫程序,能夠?qū)⒅辽?0個(gè)漢字隱藏到一幅24位的bmp格式的圖片中。
(2)用RSA算法將需要隱藏的信息進(jìn)行加密,然后再隱藏。
(3)能使用密鑰將隱藏信息解密提取出來(lái)。
三、實(shí)現(xiàn)步驟
1、找一幅bmp的24位圖片。
2、通過(guò)網(wǎng)絡(luò)學(xué)習(xí)RSA算法和LSB算法的相關(guān)原理和操作。
3、理清程序的運(yùn)行流程設(shè)計(jì)好頁(yè)面。
4、在NetBeansIDE編寫代碼實(shí)現(xiàn)相關(guān)功能。
5、調(diào)試程序并進(jìn)行優(yōu)化。
四、軟件功能及分析
1、工程結(jié)構(gòu)圖。




圖1 工程結(jié)構(gòu)
分析說(shuō)明:
圖1中PrivateKey為私鑰封裝類,Publickey為公鑰封裝類,RSAGeneratorKey為生成密鑰對(duì)的類,RSAUtil為含有加密和解密方法的封裝類,RsaKeyPair為密鑰對(duì)封裝類,_LSB_BMP為包含信息加密解密等方法的主類。
2、程序運(yùn)行初始界面。

圖2 初始界面
分析說(shuō)明:
圖2顯示的界面由標(biāo)題欄、菜單欄、圖片顯示區(qū)和文本輸入顯示區(qū)構(gòu)成。其中菜單欄中有文件、LSB和加密隱藏三個(gè)選項(xiàng),“文件”選項(xiàng)主要用于打開(kāi)已有的未加密圖片和加密圖片及保存隱藏信息后的圖片,打開(kāi)和保存的圖片均為bmp格式;“LSB”主要用于圖片的非加密隱藏和直接顯示隱藏信息;“加密隱藏”選項(xiàng)主要用于將所需的隱藏信息進(jìn)行RSA加密及將加密后的信息通過(guò)私鑰進(jìn)行解密。
3、點(diǎn)擊菜單欄中“文件”的“打開(kāi)”選項(xiàng),可選擇未加密信息的圖片或者含隱藏信息的圖片;若點(diǎn)擊“保存”選項(xiàng),則可以將含隱藏信息的圖片進(jìn)行保存。

圖3 選擇圖片路徑

圖4 打開(kāi)未隱藏信息的圖片

圖5 打開(kāi)隱藏信息的圖片

圖6 保存隱藏信息的圖片
分析說(shuō)明:
圖3中顯示的界面為選擇未隱藏信息的圖片或者隱藏了信息的圖片,圖4為打開(kāi)未隱藏信息的圖片后所出現(xiàn)的界面,且在文本輸入顯示區(qū)中顯示了可以嵌入多少字節(jié)的信息到圖片中;圖5為打開(kāi)含隱藏信息的圖片后的界面,可以看出含隱藏信息的圖片和原圖相比,憑肉眼是看不出區(qū)別的,但通過(guò)程序檢測(cè)卻能發(fā)現(xiàn)其中已經(jīng)隱藏了一定的信息;圖6為將含隱藏的圖片進(jìn)行保存,若保存成功會(huì)在文本輸入顯示區(qū)顯示“保存成功!”。
4、點(diǎn)擊菜單欄中的“加密隱藏”中的“隱藏”及“顯示”。

圖7 使用RSA對(duì)隱藏信息加密及保存私鑰

圖8 使用RSA私鑰對(duì)隱藏信息解密
分析說(shuō)明:
圖7中表示使用RSA算法將需隱藏的信息加密后,把RSA的私鑰通過(guò)文本保存的界面;圖8顯示的是通過(guò)選擇圖7保存的密鑰解密后,顯示的隱藏的信息。

源程序:
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package bmp;
  7. /**

  8. * @author 13673
  9. */
  10. import java.awt.BorderLayout;  
  11. import java.awt.Color;  
  12. import java.awt.Dimension;
  13. import java.awt.Graphics;  
  14. import java.awt.event.ActionEvent;  
  15. import java.awt.event.ActionListener;  
  16. import java.io.BufferedInputStream;  
  17. import java.io.BufferedOutputStream;  
  18. import java.io.File;  
  19. import java.io.FileInputStream;  
  20. import java.io.FileOutputStream;
  21. import java.io.IOException;
  22. import java.io.UnsupportedEncodingException;
  23. import java.math.BigInteger;
  24. import java.util.Enumeration;
  25. import java.util.logging.Level;
  26. import java.util.logging.Logger;
  27. import javax.swing.JFileChooser;  
  28. import javax.swing.JFrame;
  29. import javax.swing.JMenu;  
  30. import javax.swing.JMenuBar;  
  31. import javax.swing.JMenuItem;  
  32. import javax.swing.JPanel;  
  33. import javax.swing.JScrollPane;
  34. import javax.swing.JTextArea;
  35. import javax.swing.UIManager;
  36. import javax.swing.filechooser.FileNameExtensionFilter;
  37. import javax.swing.plaf.FontUIResource;  
  38. /**
  39. *
  40. * @ClassName: 信息隱藏_LSB技術(shù)_于BMP位圖
  41. * @Description: 基于24位BMP圖片,運(yùn)用LSB技術(shù)對(duì)文本信息進(jìn)行隱藏
  42. * @author:
  43. * @date: 2019年5月3日
  44. */
  45. public class _LSB_BMP  extends JFrame{
  46.     private static final long serialVersionUID = 1L;
  47.     RsaKeyPair keyPair=RSAGeneratorKey.generatorKey(1024);//產(chǎn)生Rsa密鑰對(duì)
  48.     boolean open_flag=false; //是否打開(kāi)圖片
  49.     int map[][];//保存像素顏色的數(shù)組 int 4個(gè)字節(jié)
  50.     int length_byte_sum=0;
  51.     MyPanel center;//繪圖面板
  52.     File selectFile;//讀取的文件
  53.     int width;//圖像寬度
  54.     int height;//圖像高度
  55.     byte temp1[];//圖像前18個(gè)字節(jié)的信息
  56.     byte temp2[];//圖像的28個(gè)字節(jié)的信息
  57.     JScrollPane scrollpane;//滑動(dòng)面板
  58.     JTextArea infoJt;//文本信息區(qū)
  59.     JMenuItem open;     //打開(kāi)文件
  60.     JMenuItem save;
  61.     JMenuItem hide;
  62.     JMenuItem show;
  63.     JMenuItem hide_rsa;
  64.     JMenuItem show_rsa;
  65.     int disWidth=1000;
  66.     int disHeight=800;
  67.     public _LSB_BMP() {  
  68.             setUIFont(new FontUIResource("微軟雅黑", 0, 20));  //設(shè)置字體
  69.         this.setLayout(new BorderLayout());//設(shè)置布局
  70.         center=new MyPanel();   //初始化畫圖面板
  71.         center.setBackground(Color.WHITE);  
  72.         center.setBackground(Color.GRAY);
  73.       //  center.setPreferredSize(new Dimension(200, 300));
  74.         scrollpane=new JScrollPane(center);//用center初始化滾動(dòng)面板  
  75.       //  scrollpane.setPreferredSize(new Dimension(200,100));
  76.         infoJt=new JTextArea();  //隱藏信息輸入的控件
  77.         infoJt.setLineWrap(true);
  78.         infoJt.setWrapStyleWord(true);
  79.        JScrollPane infoJs=new JScrollPane(infoJt);
  80.         infoJs.setPreferredSize(new Dimension(disWidth, 300));
  81.         MyListener lis=new MyListener();  //設(shè)置經(jīng)停事件  
  82.         JMenuBar menuBar=new JMenuBar();  
  83.         JMenu fileMenu=new JMenu("文件");  
  84.          open=new JMenuItem("打開(kāi)");  
  85.          save=new JMenuItem("保存");
  86.         JMenu LSBMenu=new JMenu("LSB");  
  87.          hide=new JMenuItem("隱藏");  
  88.          show=new JMenuItem("顯示");
  89.          JMenu RSAMenu=new JMenu("加密隱藏");  
  90.          hide_rsa=new JMenuItem("隱藏");  
  91.          show_rsa=new JMenuItem("顯示");
  92.         open.addActionListener(lis);  
  93.         save.addActionListener(lis);
  94.         hide.addActionListener(lis);
  95.         show.addActionListener(lis);
  96.          hide_rsa.addActionListener(lis);
  97.         show_rsa.addActionListener(lis);
  98.         fileMenu.add(open);  
  99.         fileMenu.add(save);  
  100.         menuBar.add(fileMenu);
  101.         LSBMenu.add(hide);
  102.         LSBMenu.add(show);
  103.         menuBar.add(LSBMenu);
  104.         RSAMenu.add(hide_rsa);
  105.         RSAMenu.add(show_rsa);
  106.         menuBar.add(RSAMenu);//添加到菜單欄
  107.         this.setJMenuBar(menuBar);  
  108.         this.add(scrollpane,BorderLayout.CENTER);//加入滾動(dòng)面板
  109.         this.add(infoJs,BorderLayout.SOUTH);
  110.         this.setTitle("LSB隱藏器");  
  111.         this.setSize(disWidth, disHeight);
  112.         this.setLocationRelativeTo(null);//設(shè)置窗體出現(xiàn)在屏幕中間
  113.         this.setDefaultCloseOperation(3);  
  114.         this.setVisible(true);
  115.     }  
  116.     /**

  117.      * 讀取BMP文件

  118.      */  
  119.     public void readBMP()  
  120.     {  
  121.         try {  
  122.             FileInputStream fis=new FileInputStream(selectFile); //選擇文件
  123.             //讀取了一次就會(huì)依次往后移
  124.             try (BufferedInputStream bis = new BufferedInputStream(fis) //輸入的緩沖區(qū)
  125.             ) {
  126.                 //讀取了一次就會(huì)依次往后移
  127.                 byte[] wb=new byte[4];//存放寬度的字節(jié)數(shù)組
  128.                 byte[] hb=new byte[4];//存放高度的字節(jié)數(shù)組
  129.                 temp1=new byte[18];  //存放bmp前18個(gè)字節(jié)相關(guān)信息
  130.                 bis.read(temp1);//bis.skip(18);//跳過(guò)前18個(gè)byte
  131.                 String tp;
  132.                 //bis.skip(18);//跳過(guò)18個(gè)字節(jié)
  133.                 bis.read(wb);//讀取寬度
  134.                 bis.read(hb);//讀取高度
  135.                 width=byteToint(wb);
  136.                 System.out.println("wb:\""+width+"\"");
  137.                 height=byteToint(hb);
  138.                 System.out.println("hb:\""+height+"\"");
  139.                 map=new int[height][width];//保存圖像的像素點(diǎn)的數(shù)組
  140.                 int skip=4-width*3%4;//得到每行要跳過(guò)的數(shù)字(與windows 系統(tǒng)機(jī)制有關(guān))
  141.                 //使用調(diào)色板,然后前三個(gè)字節(jié)是顏色分量,最后個(gè)為空所以跳過(guò)
  142.                 temp2=new byte[28];  //bis.skip(28);
  143.                 bis.read(temp2);//bis.skip(28);
  144.                 if(temp1[10]==55)//偏移量為55,此位圖已經(jīng)隱入了信息數(shù)據(jù)
  145.                     bis.read();//跳過(guò)1字節(jié)
  146.                 for(int i=height-1;i>0;i--)
  147.                 {
  148.                     for(int j=0;j<width;j++)
  149.                     {
  150.                         int blue=bis.read();  //讀取顏色的分量
  151.                         int green=bis.read();
  152.                         int red=bis.read();//
  153.                         Color c=new Color(red,green,blue);
  154.                         map[i][j]=c.getRGB(); //將RGB分量存入數(shù)組中
  155.                     }
  156.                     if(skip!=4)
  157.                         bis.skip(skip);  
  158.                     
  159.                 }
  160.             } //存放寬度的字節(jié)數(shù)組
  161.             center.setPreferredSize(new Dimension(width,height));  
  162.             javax.swing.SwingUtilities.updateComponentTreeUI(center);//這里必須要用updateComponentTreeUI(center)函數(shù)  
  163.         //不能用repaint()函數(shù)  
  164.         } catch (IOException e) {  
  165.         }  
  166.     }  

  167.      //保存bmp
  168.     public void writeBMP()  
  169.     {  
  170.         try {  
  171.             try (FileOutputStream fos = new FileOutputStream(selectFile)) {
  172.                 BufferedOutputStream bos=new BufferedOutputStream(fos);
  173.                 bos.write(temp1);//  心如頭部文件
  174.                 bos.write(intTobyte(width,4));//寬度
  175.                 bos.write(intTobyte(height,4));//高度
  176.                 bos.write(temp2);
  177.                 int skip=4-width*3%4;//得到每行要跳過(guò)的數(shù)字(與windows 系統(tǒng)機(jī)制有關(guān))
  178.                 if(temp1[10]==55)
  179.                     bos.write(new byte[1]);
  180.                 for(int i=height-1;i>=0;i--)
  181.                 {
  182.                     for(int j=0;j<width;j++)
  183.                     {
  184.                         Color c=new Color(map[i][j]);
  185.                         int blue=c.getBlue();
  186.                         int green=c.getGreen();
  187.                         int red=c.getRed();
  188.                         bos.write(blue);  //寫入之前存放的像素點(diǎn)分量
  189.                         bos.write(green);
  190.                         bos.write(red);
  191.                     }
  192.                     if(skip!=4)
  193.                         bos.write(new byte[skip]);
  194.                 }
  195.                 bos.flush();
  196.             }  
  197.         } catch (IOException e) {  
  198.         }  
  199.     }  
  200.     //字節(jié)轉(zhuǎn)int  
  201.     public static  int byteToint(byte b[])  
  202.     {  
  203.         int t1=(b[3]&0xff)<<24;  
  204.         int t2=(b[2]&0xff)<<16;  
  205.         int t3=(b[1]&0xff)<<8;  
  206.         int t4=b[0]&0xff;  
  207.        //System.out.println(b[1]&0xff);//輸出的是一個(gè)整形數(shù)據(jù)  
  208.        //在java中,設(shè)計(jì)int和比int位數(shù)來(lái)的小的類型b,如byte,char等,都是先把小類型擴(kuò)展成int再來(lái)運(yùn)算,  ??????  
  209.               //return( t1<<24)+(t2<<16)+(t3<<8)+t4;//必須加括號(hào)
  210.         return t1+t2+t3+t4;  
  211.     }  
  212.     public static  int byteToint1(byte b[])  
  213.     {  
  214.       
  215.         int t3=(b[1]&0xff)<<8;  
  216.         int t4=b[0]&0xff;  
  217.        //System.out.println(b[1]&0xff);//輸出的是一個(gè)整形數(shù)據(jù)  
  218.        //在java中,設(shè)計(jì)int和比int位數(shù)來(lái)的小的類型b,如byte,char等,都是先把小類型擴(kuò)展成int再來(lái)運(yùn)算,  ??????  
  219.               //return( t1<<24)+(t2<<16)+(t3<<8)+t4;//必須加括號(hào)
  220.         return t3+t4;  
  221.     }

  222.     //int 轉(zhuǎn)字節(jié)

  223.     public static byte[] intTobyte(int a,int len)  

  224.     {  

  225.         byte []t=new byte[len];  
  226.             t[0]=(byte) ((a&0xff));  
  227.             if(len>1)  
  228.             t[1]=(byte)((a&0xff00)>>8);  
  229.             if(len>2)  
  230.             t[2]=(byte)((a&0xff0000)>>16);  
  231.             if(len>3)  
  232.             t[3]=(byte)((a&0xff000000)>>24);  
  233.         return t;  
  234.     }  

  235.    

  236.     private static void setUIFont(javax.swing.plaf.FontUIResource f) {
  237.                 Enumeration<Object> keys = UIManager.getDefaults().keys();
  238.                 while (keys.hasMoreElements()) {
  239.                         Object key = keys.nextElement();
  240.                         Object value = UIManager.get(key);
  241.                         if (value instanceof javax.swing.plaf.FontUIResource) {
  242.                                 UIManager.put(key, f);
  243.                         }
  244.                 }
  245.         }   
  246.     /**
  247.      * LSB處理
  248.      * @author
  249.      * @date 2019年5月3日
  250.      */
  251.     class LSB{
  252.         public  boolean hide(boolean flag) {
  253.             FileNameExtensionFilter filter=new FileNameExtensionFilter("文本文檔(*.txt)", "txt");
  254.             JFileChooser fileChosser = new JFileChooser();  
  255.             fileChosser.setFileFilter(filter);  
  256.             fileChosser.setSelectedFile(new File("密鑰.txt"));
  257.             fileChosser.setCurrentDirectory(new File("\\"));
  258.             String info="";
  259.             System.out.println("temp1【10】:"+temp1[10]);
  260.             temp1[10]+=1;//將位圖數(shù)據(jù)偏移量增1,作為是否隱入數(shù)據(jù)的標(biāo)識(shí),此時(shí)temp1[10]=55;
  261.             System.out.println("temp1【10】:"+temp1[10]);
  262.             if(!flag)
  263.                     info=infoJt.getText(); //獲取的隱藏信息
  264.             else{
  265.                 String mingwen = "0"+infoJt.getText();
  266.                 info=RSAUtil.encrypt(mingwen,keyPair.getPublicKey() ,"UTF-8");
  267.                 System.out.println("加密后:"+info);
  268.                 int choose=fileChosser.showSaveDialog(null);  
  269.                 if(choose==JFileChooser.APPROVE_OPTION)  
  270.                 {  
  271.                     selectFile=fileChosser.getSelectedFile();  
  272.                      try {  
  273.                             FileOutputStream fos=new FileOutputStream(selectFile);  
  274.                             BufferedOutputStream bos=new BufferedOutputStream(fos);
  275.                             byte[] N=keyPair.getPublicKey().getN().toString().getBytes();
  276.                             byte[] privateKey=keyPair.getPrivateKey().getA().toString().getBytes();
  277.                             String maohao=":";  
  278.                             byte[] mao=maohao.getBytes();
  279.                             length_byte_sum=N.length+privateKey.length+maohao.getBytes().length;
  280.                             System.out.println("length_byte_sum"+length_byte_sum);
  281.                             byte[] len=String.valueOf(length_byte_sum).getBytes();
  282.                            // bos.write(length_byte_sum);
  283.                             bos.write(len);//  
  284.                             bos.write(N);//   
  285.                             bos.write(mao);//   
  286.                             bos.write(privateKey);//   
  287.                             bos.flush();  
  288.                             fos.close();  
  289.                          } catch (IOException e) {  
  290.                  
  291.                         }  
  292.             
  293.                 }else{
  294.                     return false;
  295.                 }
  296.            
  297.                         
  298.                     }
  299.             
  300.              infoJt.setText("保存成功!");
  301.                         System.out.println("隱藏信息:"+info);
  302.                             char[] infoChs=info.toCharArray(); //將隱藏信息轉(zhuǎn)成字符數(shù)組                       
  303.                         System.out.println("隱藏信息長(zhǎng)度"+infoChs.length);
  304.                             int index=0,endIndex=0;
  305.                             String str;
  306.                             byte[] infoBins=new byte[infoChs.length*16];//隱藏信息的字符長(zhǎng)度  
  307.                         //     二進(jìn)制字符串                     一個(gè)字符兩個(gè)字節(jié) 轉(zhuǎn)成16位
  308.                             char[] wordBins=new char[16];
  309.                          //   字節(jié)二進(jìn)制字符串                  
  310.                          //將每個(gè)字節(jié)隱藏的信
  311.                             for(int i=0;i<infoChs.length;i++) {
  312.                                     str=intToWordBinaryString((int)infoChs[i]);
  313.                                 //把int轉(zhuǎn)成二進(jìn)制字符串  7   111
  314.                                 //把每個(gè)字符都轉(zhuǎn)成對(duì)應(yīng)的二進(jìn)制字符串
  315.                                //   System.out.print(str+"  ");
  316.                                     str=new StringBuilder(str).reverse().toString();
  317.                              //    System.out.print(str+"  ");
  318.                                 //reverse 逆序轉(zhuǎn)換  123 321
  319.                                     wordBins=str.toCharArray();
  320.                                     for(int j=0;j<16;j++) {
  321.                                  //   System.out.print(wordBins[j]);
  322.                         
  323.                                             infoBins[index++]=(byte)(wordBins[j]-'0');     
  324.                                  //反向加密
  325.                                     }
  326.                              //  System.out.println();
  327.                             }
  328.                        
  329.                         //隱藏信息
  330.                             index=0;
  331.                             for(int i=height-1;i>0;i--) //hang
  332.                     for(int j=0;j<width;j++)  //lie
  333.                     {        //infoBins 已經(jīng)將信息轉(zhuǎn)換成字節(jié)反向的二進(jìn)制字符串
  334.                             if(index<infoBins.length) {
  335.                               
  336.                                     map[i][j]=map[i][j]&0xfffffffe;  //int 4個(gè)字節(jié)                              
  337.                                 //數(shù)據(jù)末尾位清洗為0
  338.                                 //如果infoBins的位為1則將map對(duì)應(yīng)像素點(diǎn)加1
  339.                                     if(infoBins[index]==1) {
  340.                                             map[i][j]+=1;
  341.                                     }
  342.                                //  System.out.print(map[i][j]+" ");
  343.                                     index++;
  344.                             }
  345.                             else
  346.                             {
  347.                                     map[i][j]=map[i][j]&0xfffffffe;//結(jié)束標(biāo)記,一個(gè)字的最低位為0
  348.                                     endIndex++;
  349.                                     if(endIndex>=16)
  350.                                     return true;
  351.                             }
  352.                 }            
  353.             
  354.                    return false;            
  355.             }        
  356.             public String show(boolean flag) throws UnsupportedEncodingException {
  357.             byte temp[] = null;
  358.             FileNameExtensionFilter filter=new FileNameExtensionFilter("文本文檔(*.txt)", "txt");
  359.             JFileChooser fileChosser = new JFileChooser();  
  360.             fileChosser.setFileFilter(filter);  
  361.             fileChosser.setCurrentDirectory(new File("\\"));
  362.                     String info="";
  363.                     byte[] wordBins=new byte[16];
  364.                     int index=0;
  365.                     String wordStr="";
  366.                     int wordInt;
  367.                     outer:for(int i=height-1;i>=0;i--) {
  368.                             for(int j=0;j<width;j++) {
  369.                                    wordBins[index++]=(byte)(map[i][j]&0x00000001);
  370.                                     if(index>=16) {
  371.                                             for(int k=15;k>=0;k--) {
  372.                                                     wordStr+=wordBins[k];
  373.                                             }
  374.                                             wordInt=Integer.parseInt(wordStr,2);
  375.                                             if(wordInt!=0) {
  376.                                                     info+=(char)wordInt;
  377.                                             }else {
  378.                                                     break outer;
  379.                                             }
  380.                                             index=0;wordStr="";
  381.                                     }
  382.                             }
  383.                     }
  384.                 String infor=info;
  385.                 String result=null;
  386.                 if(!flag)
  387.                     result = infor;
  388.                 else
  389.                 {
  390.                     int choose=fileChosser.showOpenDialog(null);  
  391.                     if(choose==JFileChooser.APPROVE_OPTION)//點(diǎn)擊的是確定按鈕   
  392.                     {  
  393.                            selectFile=fileChosser.getSelectedFile();  
  394.                      try {  
  395.                         FileInputStream fis=new FileInputStream(selectFile); //選擇文件
  396.                         BufferedInputStream bis=new BufferedInputStream(fis); //輸入的緩沖區(qū)
  397.                         byte[] wb=new byte[4];//存放寬度的字節(jié)數(shù)組
  398.                         bis.read(wb);
  399.                         System.out.println("wb:::"+ new String (wb));
  400.                         int len=Integer.parseInt( new String (wb) );
  401.                         temp =new byte[len];
  402.                         bis.read(temp);           
  403.                         bis.close();  
  404.                         String str= new String (temp);
  405.                         String[] sub=str.split(":");
  406.                         System.out.println("sub[0]"+sub[0]);
  407.                         System.out.println("sub[1]"+sub[1]);
  408.                         BigInteger n=new BigInteger(sub[0]);
  409.                         BigInteger a=new BigInteger(sub[1]);
  410.                         PrivateKey p =new PrivateKey( n,a);
  411.                         result=RSAUtil.decrypt(infor, p,"UTF-8");
  412.                          } catch (Exception e) {  
  413.                          }
  414.                      
  415.                     }
  416.                     
  417.                 }
  418.                     return result;
  419.             }
  420.             private String intToWordBinaryString(int i) {
  421.                         StringBuilder sb = new StringBuilder(Integer.toBinaryString(i));
  422.                         while (sb.length() < 16) {
  423.                                 sb.insert(0, "0");
  424.                         }
  425.                         return sb.toString();
  426.                 }
  427.     }
  428.     /**
  429.      * 顯示面板
  430.      *
  431.      *
  432.      */  
  433.     class MyPanel extends JPanel{  
  434.         private static final long serialVersionUID = 1L;
  435.         public void paint(Graphics g) {  
  436.         super.paint(g);  
  437.         if(map!=null)  
  438.            {  
  439.                 for(int i=0;i<map.length;i++)  
  440.                 {  
  441.                     for(int j=0;j<map[i].length;j++)  
  442.                     {  
  443.                         g.setColor(new Color(map[i][j]));  
  444.                         g.drawLine(j+200, i, j+200, i);

  445.                     }
  446.                 }  
  447.             }  
  448.         }  
  449.     }      
  450.     class MyListener implements ActionListener{  
  451.         JFileChooser fileChosser;  
  452.         //文件選擇控件
  453.         MyListener()  
  454.         {  
  455.             FileNameExtensionFilter filter=new FileNameExtensionFilter("24位位圖(*.bmp)", "bmp");
  456.             fileChosser=new JFileChooser();  
  457.             fileChosser.setFileFilter(filter);  
  458.             fileChosser.setCurrentDirectory(new File("\\"));  
  459.         }  
  460.         public void actionPerformed(ActionEvent e) {
  461.                 JMenuItem jmi = (JMenuItem) e.getSource();
  462.             if(jmi==open)//選擇的是打開(kāi)  
  463.             {  
  464.                 open_flag=true;
  465.                int choose=fileChosser.showOpenDialog(null);  
  466.                 if(choose==JFileChooser.APPROVE_OPTION)//點(diǎn)擊的是確定按鈕   
  467.                 {  
  468.                     selectFile=fileChosser.getSelectedFile();  
  469.                     readBMP();
  470.                     infoJt.setText("圖片打開(kāi)成功!\n");
  471.                     if(temp1[10]==54) {
  472.                     infoJt.append("最多可嵌入"+height*width/8+"個(gè)字節(jié)的信息!\n");
  473.                     }else if(temp1[10]==55) {
  474.                       infoJt.append("此圖片已經(jīng)隱入有信息!");
  475.                     }
  476.                 }
  477.             }  
  478.             else if(jmi==save)//選擇的是保存
  479.             {  
  480.                 if(open_flag){
  481.                     int choose=fileChosser.showSaveDialog(null);  
  482.                     if(choose==JFileChooser.APPROVE_OPTION)  
  483.                     {  
  484.                          selectFile=fileChosser.getSelectedFile();  
  485.                          writeBMP();  
  486.                          infoJt.setText("保存成功!");
  487.                     }  
  488.                 }else{
  489.                         infoJt.setText("請(qǐng)先打開(kāi)圖片!");
  490.                 }
  491.                
  492.             }
  493.             else if(jmi==hide) {
  494.                 if(open_flag){
  495.                     if(new LSB().hide(false)) {
  496.                            infoJt.setText("信息隱入成功!");
  497.                     }else{
  498.                             infoJt.setText("信息隱入出現(xiàn)不確定問(wèn)題!");
  499.                     }
  500.                 }else{
  501.                      infoJt.setText("請(qǐng)先打開(kāi)圖片!");
  502.                 }
  503.             }
  504.              else if(jmi==hide_rsa) {
  505.                 if(open_flag){
  506.                     if(new LSB().hide(true)) {
  507.                            infoJt.setText("信息隱入成功(RSA加密)!");
  508.                     }else{
  509.                             infoJt.setText("信息隱入出現(xiàn)不確定問(wèn)題!");
  510.                     }
  511.                 }else{
  512.                     infoJt.setText("請(qǐng)先打開(kāi)圖片!");
  513.                 }
  514.             }
  515.             else if(jmi==show) {
  516.                  if(open_flag){
  517.                     try {
  518.                         String info=new LSB().show(false);
  519.                         infoJt.setText("隱入的信息內(nèi)容\n");
  520.                         infoJt.append(info);
  521.                     } catch (UnsupportedEncodingException ex) {
  522.                         Logger.getLogger(_LSB_BMP.class.getName()).log(Level.SEVERE, null, ex);
  523.                     }
  524.                  }else{
  525.                      infoJt.setText("請(qǐng)先打開(kāi)圖片!");
  526.                  }
  527.             }
  528.             else if(jmi==show_rsa) {
  529.                     if(open_flag){
  530.                 try {
  531.                         String info=new LSB().show(true);
  532.                         infoJt.setText("隱入的信息內(nèi)容(RSA解密!)\n");
  533.                         infoJt.append(info);
  534.                     } catch (UnsupportedEncodingException ex) {
  535.                         Logger.getLogger(_LSB_BMP.class.getName()).log(Level.SEVERE, null, ex);
  536.                     }
  537.                     }else{
  538.                         infoJt.setText("請(qǐng)先打開(kāi)圖片!");
  539.                     }
  540.             }
  541.         }  
  542.     }  
  543.     public static void main(String[] args) {  
  544.        new _LSB_BMP();
  545.     }  
  546. }   
復(fù)制代碼


全部資料51hei下載地址:
LSB,RSA的圖片隱藏技術(shù).zip (41.2 KB, 下載次數(shù): 11)
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 欧美日本久久 | 黄网免费看 | 成人av一区二区亚洲精 | 在线免费观看a级片 | 国产精成人 | 天天想天天干 | 中文字幕人成乱码在线观看 | 国产高清在线精品 | 久久精品久久久久久 | 国产日韩精品一区 | 麻豆av在线免费观看 | 国产伦精品一区二区三区精品视频 | 午夜影视免费片在线观看 | 国产丝袜一区二区三区免费视频 | 国产日韩精品在线 | 亚洲人成人一区二区在线观看 | 香蕉视频91 | 福利视频大全 | 刘亦菲国产毛片bd | 色屁屁在线观看 | 亚洲成人三级 | 中文字幕一区二区三区四区不卡 | 精品一区二区三区在线视频 | 国产日韩精品久久 | 国产精品一区二区三区四区 | 九九久久精品 | 亚洲日日 | 日日操日日舔 | 午夜国产| 亚洲精精品 | 国产亚洲精品久久午夜玫瑰园 | 国产精品永久 | 精品一区二区三区在线视频 | m豆传媒在线链接观看 | 成人亚洲网 | 狠狠做深爱婷婷综合一区 | 精品久久久久久 | 中文字幕a√ | 久久久久国产精品 | av一区二区三区在线观看 | 成人免费高清 |