如何使用线程方法并行处理rsa算法. [英] How to parallel a rsa algorithm using a thread method .

查看:59
本文介绍了如何使用线程方法并行处理rsa算法.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
我去年在做msc(cs).这是我的项目,我在rsa,DSA,ECIES,算法中有顺序代码.该代码如何在并发Java中并行或使用线程..
RSA ALGORITHM

Hi.
I am doing msc (cs) final year .This my project, I have Sequential code in rsa ,DSA,ECIES, algorithm .That code how to parallel in concurrent java or use a thread ..
RSA ALGORITHM

import java.security.KeyPairGenerator;
import java.security.KeyPair;
import java.security.PublicKey;
import java.security.PrivateKey;
import javax.crypto.Cipher;
import sun.misc.BASE64Encoder;
import javax.swing.JOptionPane;

public class rsa {
  private static byte[] encrypt(byte[] inpBytes, PublicKey key,
      String xform) throws Exception {
    Cipher cipher = Cipher.getInstance(xform);
    cipher.init(Cipher.ENCRYPT_MODE, key);
    return cipher.doFinal(inpBytes);
  }
  private static byte[] decrypt(byte[] inpBytes, PrivateKey key,
      String xform) throws Exception{
    Cipher cipher = Cipher.getInstance(xform);
    cipher.init(Cipher.DECRYPT_MODE, key);
    return cipher.doFinal(inpBytes);
  }

  public static void main(String[] unused) throws Exception {
    String xform = "RSA/NONE/PKCS1PADDING";
    // Generate a key-pair
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(1024); // 1024 is the keysize.
    KeyPair kp = kpg.generateKeyPair();
    PublicKey pubk = kp.getPublic();
    PrivateKey prvk = kp.getPrivate();
     // get the text to encrypt
    String inputText = JOptionPane.showInputDialog("Input your message: ");

    byte[] dataBytes =inputText.getBytes();

    byte[] encBytes = encrypt(dataBytes, pubk, xform);
    //System.out.println(encBytes);
    byte[] decBytes = decrypt(encBytes, prvk, xform);
    //System.out.println(decBytes);
    boolean expected = java.util.Arrays.equals(dataBytes, decBytes);
   if(expected)
   { 
     // and display the results
    JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
                                  "Encrypted Text :\n " + new BASE64Encoder().encode(encBytes) + "\n\n" +
                                  "Decrypted Text : " + new String(decBytes) + "\n\n" + "Test SUCCEEDDED");
    }
    else<code></code>
    {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
                                  "Encrypted Text : \n" + new BASE64Encoder().encode(encBytes) + "\n\n" +
                                  "Decrypted Text : " + new String(decBytes) + "\n\n" + "Test FAILED");

     
     }
    
  }
}

推荐答案

您好,使用已发布代码中的sequencei算法.如果您的项目需要并行的项目,那么您必须开发(即编写)这样的算法:您的起点应该是算法文档,并且可能是一些实现顺序项目的可用开源项目的源代码.
:-)
Well you''re using the sequentiali algorithm in the posted code. If you project requires the parallel one then you have to develop (i.e. write) such an algorithm: your starting point should be the algorithm documentation and possibly the source codes of some available open source project implementing the sequential one.
:-)


这篇关于如何使用线程方法并行处理rsa算法.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆