congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
RSAPrivateKey.getPrivateExponent
Code IndexAdd Tabnine 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)

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

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

JCERSAPrivateKey(
  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

  • Start an intent from android
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getSharedPreferences (Context)
  • setContentView (Activity)
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Join (org.hibernate.mapping)
  • Table (org.hibernate.mapping)
    A relational table
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now