Codota Logo
RSAPrivateKey.getPrivateExponent
Code IndexAdd Codota to your IDE (free)

How to use
getPrivateExponent
method
in
java.security.interfaces.RSAPrivateKey

Best Java code snippets using java.security.interfaces.RSAPrivateKey.getPrivateExponent (Showing top 20 results out of 612)

  • Common ways to obtain RSAPrivateKey
private void myMethod () {
RSAPrivateKey r =
  • Codota IconKeyFactory keyFactory;KeySpec keySpec;(RSAPrivateKey) keyFactory.generatePrivate(keySpec)
  • Codota IconKeyPair keyPair;(RSAPrivateKey) keyPair.getPrivate()
  • Codota IconQute.libg.cryptography.RSA rSA;BigInteger modulus;BigInteger privateExponent;rSA.create(new RSAPrivateKeySpec(modulus, privateExponent))
  • Smart code suggestions by Codota
}
origin: alibaba/druid

public static String encrypt(byte[] keyBytes, String plainText)
    throws Exception {
  PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
  KeyFactory factory = KeyFactory.getInstance("RSA", "SunRsaSign");
  PrivateKey privateKey = factory.generatePrivate(spec);
  Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
  try {
    cipher.init(Cipher.ENCRYPT_MODE, privateKey);
  } catch (InvalidKeyException e) {
    //For IBM JDK, 原因请看解密方法中的说明
    RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) privateKey;
    RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(rsaPrivateKey.getModulus(), rsaPrivateKey.getPrivateExponent());
    Key fakePublicKey = KeyFactory.getInstance("RSA").generatePublic(publicKeySpec);
    cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.ENCRYPT_MODE, fakePublicKey);
  }
  byte[] encryptedBytes = cipher.doFinal(plainText.getBytes("UTF-8"));
  String encryptedString = Base64.byteArrayToBase64(encryptedBytes);
  return encryptedString;
}
origin: wildfly/wildfly

RawRSAPrivateKey(final RSAPrivateKey original) {
  super(original);
  privateExponent = original.getPrivateExponent();
  modulus = original.getModulus();
}
origin: wildfly/wildfly

  boolean isEqual(final RSAPrivateKey key) {
    return super.isEqual(key) && Objects.equals(privateExponent, key.getPrivateExponent()) && Objects.equals(modulus, key.getModulus());
  }
}
origin: mpusher/mpush

private static void test() {
  Pair<RSAPublicKey, RSAPrivateKey> pair = RSAUtils.genKeyPair(RAS_KEY_SIZE);
  //生成公钥和私钥
  RSAPublicKey publicKey = pair.key;
  RSAPrivateKey privateKey = pair.value;
  //模
  String modulus = publicKey.getModulus().toString();
  //公钥指数
  String public_exponent = publicKey.getPublicExponent().toString();
  //私钥指数
  String private_exponent = privateKey.getPrivateExponent().toString();
  //明文
  byte[] ming = "123456789".getBytes(Constants.UTF_8);
  System.out.println("明文:" + new String(ming, Constants.UTF_8));
  //使用模和指数生成公钥和私钥
  RSAPrivateKey priKey = RSAUtils.getPrivateKey(modulus, private_exponent);
  RSAPublicKey pubKey = RSAUtils.getPublicKey(modulus, public_exponent);
  System.out.println("privateKey=" + priKey);
  System.out.println("publicKey=" + pubKey);
  //加密后的密文
  byte[] mi = RSAUtils.encryptByPublicKey(ming, pubKey);
  System.out.println("密文:" + new String(mi, Constants.UTF_8));
  //解密后的明文
  ming = RSAUtils.decryptByPrivateKey(mi, priKey);
  System.out.println("解密:" + new String(ming, Constants.UTF_8));
}
origin: com.alibaba/druid

public static String encrypt(byte[] keyBytes, String plainText)
    throws Exception {
  PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
  KeyFactory factory = KeyFactory.getInstance("RSA", "SunRsaSign");
  PrivateKey privateKey = factory.generatePrivate(spec);
  Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
  try {
    cipher.init(Cipher.ENCRYPT_MODE, privateKey);
  } catch (InvalidKeyException e) {
    //For IBM JDK, 原因请看解密方法中的说明
    RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) privateKey;
    RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(rsaPrivateKey.getModulus(), rsaPrivateKey.getPrivateExponent());
    Key fakePublicKey = KeyFactory.getInstance("RSA").generatePublic(publicKeySpec);
    cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.ENCRYPT_MODE, fakePublicKey);
  }
  byte[] encryptedBytes = cipher.doFinal(plainText.getBytes("UTF-8"));
  String encryptedString = Base64.byteArrayToBase64(encryptedBytes);
  return encryptedString;
}
origin: resteasy/Resteasy

/**
* Decrypts the specified encrypted Content Encryption Key (CEK).
*
* @param priv         The private RSA key. Must not be {@code null}.
* @param encryptedCEK The encrypted Content Encryption Key (CEK) to
*                     decrypt. Must not be {@code null}.
*
* @return The decrypted Content Encryption Key (CEK).
*
* @throws RuntimeException If decryption failed.
*/
public static SecretKey decryptCEK(final RSAPrivateKey priv,
               final byte[] encryptedCEK)
 throws RuntimeException {
 try {
   RSAEngine engine = new RSAEngine();
   OAEPEncoding cipher = new OAEPEncoding(engine);
   BigInteger mod = priv.getModulus();
   BigInteger exp = priv.getPrivateExponent();
   RSAKeyParameters keyParams = new RSAKeyParameters(true, mod, exp);
   cipher.init(false, keyParams);
   byte[] secretKeyBytes = cipher.processBlock(encryptedCEK, 0, encryptedCEK.length);
   return new SecretKeySpec(secretKeyBytes, "AES");
 } catch (Exception e) {
   // org.bouncycastle.crypto.InvalidCipherTextException
   throw new RuntimeException(Messages.MESSAGES.couldntDecryptCEK(e.getLocalizedMessage()), e);
 }
}
origin: i2p/i2p.i2p

/**
 *  As of 0.9.31, if pk is a RSAPrivateCrtKey,
 *  this will return a RSASigningPrivateCrtKey.
 */
public static SigningPrivateKey fromJavaKey(RSAPrivateKey pk, SigType type)
             throws GeneralSecurityException {
  // private key is modulus (pubkey) + exponent
  BigInteger n = pk.getModulus();
  BigInteger d = pk.getPrivateExponent();
  byte[] b = combine(n, d, type.getPrivkeyLen());
  if (pk instanceof RSAPrivateCrtKey)
    return RSASigningPrivateCrtKey.fromJavaKey((RSAPrivateCrtKey) pk);
  return new SigningPrivateKey(type, b);
}
origin: RUB-NDS/TLS-Attacker

public static BigInteger extractRSAPrivateExponent(PrivateKey key) throws IOException {
  if (key instanceof RSAPrivateKey) {
    return ((RSAPrivateKey) ((RSAPrivateKey) key)).getPrivateExponent();
  } else {
    return null;
  }
}
origin: biz.aQute.bnd/biz.aQute.bndlib

public static String toString(Object key) {
  if (key instanceof RSAPrivateKey) {
    RSAPrivateKey pk = (RSAPrivateKey) key;
    return "RSA.Private(" + pk.getModulus() + ":" + pk.getPrivateExponent() + ")";
  }
  if (key instanceof RSAPublicKey) {
    RSAPublicKey pk = (RSAPublicKey) key;
    return "RSA.Private(" + pk.getModulus() + ":" + pk.getPublicExponent() + ")";
  }
  return null;
}
origin: ibinti/bugvm

JCERSAPrivateKey(
  RSAPrivateKey key)
{
  this.modulus = key.getModulus();
  this.privateExponent = key.getPrivateExponent();
}
origin: ibinti/bugvm

BCRSAPrivateKey(
  RSAPrivateKey key)
{
  this.modulus = key.getModulus();
  this.privateExponent = key.getPrivateExponent();
}
origin: biz.aQute/bndlib

public static String toString(Object key) {
  if (key instanceof RSAPrivateKey) {
    RSAPrivateKey pk = (RSAPrivateKey) key;
    return "RSA.Private(" + pk.getModulus() + ":" + pk.getPrivateExponent() + ")";
  }
  if (key instanceof RSAPublicKey) {
    RSAPublicKey pk = (RSAPublicKey) key;
    return "RSA.Private(" + pk.getModulus() + ":" + pk.getPublicExponent() + ")";
  }
  return null;
}
origin: org.wildfly.security/wildfly-elytron

RawRSAPrivateKey(final RSAPrivateKey original) {
  super(original);
  privateExponent = original.getPrivateExponent();
  modulus = original.getModulus();
}
origin: com.madgag.spongycastle/prov

JCERSAPrivateKey(
  RSAPrivateKey key)
{
  this.modulus = key.getModulus();
  this.privateExponent = key.getPrivateExponent();
}
origin: org.wildfly.security/wildfly-elytron-credential

RawRSAPrivateKey(final RSAPrivateKey original) {
  super(original);
  privateExponent = original.getPrivateExponent();
  modulus = original.getModulus();
}
origin: org.bouncycastle/bcprov-debug-jdk15on

JCERSAPrivateKey(
  RSAPrivateKey key)
{
  this.modulus = key.getModulus();
  this.privateExponent = key.getPrivateExponent();
}
origin: biz.aQute.bnd/biz.aQute.bnd

public static String toString(Object key) {
  if (key instanceof RSAPrivateKey) {
    RSAPrivateKey pk = (RSAPrivateKey) key;
    return "RSA.Private(" + pk.getModulus() + ":" + pk.getPrivateExponent() + ")";
  }
  if (key instanceof RSAPublicKey) {
    RSAPublicKey pk = (RSAPublicKey) key;
    return "RSA.Private(" + pk.getModulus() + ":" + pk.getPublicExponent() + ")";
  }
  return null;
}
origin: org.jboss.eap/wildfly-client-all

RawRSAPrivateKey(final RSAPrivateKey original) {
  super(original);
  privateExponent = original.getPrivateExponent();
  modulus = original.getModulus();
}
origin: org.osgi/osgi.enroute.web.simple.provider

public static String toString(Object key) {
  if (key instanceof RSAPrivateKey) {
    RSAPrivateKey pk = (RSAPrivateKey) key;
    return "RSA.Private(" + pk.getModulus() + ":" + pk.getPrivateExponent() + ")";
  }
  if (key instanceof RSAPublicKey) {
    RSAPublicKey pk = (RSAPublicKey) key;
    return "RSA.Private(" + pk.getModulus() + ":" + pk.getPublicExponent() + ")";
  }
  return null;
}
origin: org.xipki.tk/security

public static RSAKeyParameters generateRSAPrivateKeyParameter(final RSAPrivateKey key) {
  ParamUtil.requireNonNull("key", key);
  if (key instanceof RSAPrivateCrtKey) {
    RSAPrivateCrtKey rsaKey = (RSAPrivateCrtKey) key;
    return new RSAPrivateCrtKeyParameters(rsaKey.getModulus(), rsaKey.getPublicExponent(),
        rsaKey.getPrivateExponent(), rsaKey.getPrimeP(), rsaKey.getPrimeQ(),
        rsaKey.getPrimeExponentP(), rsaKey.getPrimeExponentQ(),
        rsaKey.getCrtCoefficient());
  } else {
    return new RSAKeyParameters(true, key.getModulus(), key.getPrivateExponent());
  }
}
java.security.interfacesRSAPrivateKeygetPrivateExponent

Javadoc

Returns the private exponent d.

Popular methods of RSAPrivateKey

  • getModulus
  • getEncoded
  • getFormat
  • <init>
  • getAlgorithm

Popular in Java

  • Making http post requests using okhttp
  • getSupportFragmentManager (FragmentActivity)
  • getSharedPreferences (Context)
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • IOException (java.io)
    Signals that an I/O exception of some sort has occurred. This class is the general class of exceptio
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • TimerTask (java.util)
    A task that can be scheduled for one-time or repeated execution by a Timer.
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now