zoukankan      html  css  js  c++  java
  • Porting .Net RSA xml keys to Java

    byte[] expBytes = Base64.decodeBase64(exponentElem.getText().trim()));
    byte[] modBytes = Base64.decodeBase64(modulusElem.getText().trim());
    byte[] dBytes = Base64.decodeBase64(dElem.getText().trim());
    
    BigInteger modules = new BigInteger(1, modBytes);
    BigInteger exponent = new BigInteger(1, expBytes);
    BigInteger d = new BigInteger(1, dBytes);
    
    KeyFactory factory = KeyFactory.getInstance("RSA");
    Cipher cipher = Cipher.getInstance("RSA");
    String input = "test";
    
    RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(modules, exponent);
    PublicKey pubKey = factory.generatePublic(pubSpec);
    cipher.init(Cipher.ENCRYPT_MODE, pubKey);
    byte[] encrypted = cipher.doFinal(input.getBytes("UTF-8"));
    System.out.println("encrypted: " + new String(encrypted));
    
    RSAPrivateKeySpec privSpec = new RSAPrivateKeySpec(modules, d);
    PrivateKey privKey = factory.generatePrivate(privSpec);
    cipher.init(Cipher.DECRYPT_MODE, privKey);
    byte[] decrypted = cipher.doFinal(encrypted);
    System.out.println("decrypted: " + new String(decrypted));
  • 相关阅读:
    Loadrunner日志设置与查看
    Mysqlfunc.c
    loadrunner生成随机uuid的方法
    数据库连接
    FAQ_2
    JAVA VUser
    FAQ_1
    LoadRunner中的Web 函数列表
    MySQL性能诊断与调优
    LoadRunner书籍推荐
  • 原文地址:https://www.cnblogs.com/frankyou/p/8335063.html
Copyright © 2011-2022 走看看