Package com.encryption

Examples of com.encryption.RSAEncrypter


  }

  @Override
  public void generatePublicKey(Users user) {
    try {
      RSAEncrypter encrypt = new RSAEncrypter();

      // Generate keys
      KeyPair keyPair = encrypt.generateKey();

      /*
       * 创建以用户ID为名的文件夹 在该文件夹下保存公钥和私钥文件
       */

      String dir = "D:/hdfs/" + user.getUserId().toString();
      File directory = new File(dir);

      System.out.println(directory.mkdirs());

      encrypt.saveKey(keyPair, dir + "/publicKey", dir + "/privateKey");

      /*
       * 保存公钥的url到users表中的publicKey字段
       */
      userdao.updateUserPublicKey(user, dir + "/publicKey");
View Full Code Here


      /*
       * 利用公钥加密DES密钥
       */
      // 从文件中加载公钥
      RSAEncrypter encrypt = new RSAEncrypter();
      String publicKeyPath = "D:/hdfs/" + userId + "/publicKey";
      RSAPublicKey publicKey = (RSAPublicKey) encrypt.loadKey(
          publicKeyPath, 1);
      encryptedDataSecretKey = encrypt.encrypt(publicKey,
          key.getEncoded());
    } catch (Exception e) {
      e.printStackTrace();
    }
    return encryptedDataSecretKey;
View Full Code Here

  public InputStream decryptFile(File privateKey, long fileId, File file) {

    /*
     * 创建RSAEncrypter对象
     */
    RSAEncrypter encrypter = new RSAEncrypter();
    /*
     * 加载私钥
     */
    String privateKeyPath = privateKey.getAbsolutePath();

    RSAPrivateKey pKey = (RSAPrivateKey) encrypter.loadKey(privateKeyPath,
        0);
    /*
     * 获取fileId对应的已加密数据密钥
     */
    HdfsFile dfsfile = filedao.findFile(fileId);
    byte[] encryptDataKey = dfsfile.getEncryptDataKey();

    /*
     * RSAEncrypter 对象调用解密模块,解密已加密的数据密钥
     */
    byte[] dataKey = encrypter.decrypt(pKey, encryptDataKey);

    /*
     * 根据数据密钥,构造DesEncrypter对象
     */
    // Create encrypter/decrypter class
View Full Code Here

TOP

Related Classes of com.encryption.RSAEncrypter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.