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

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

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

  • 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

/**
 * 私钥解密
 *
 * @param data       待加密数据
 * @param privateKey 私钥
 * @return 解密后的值
 */
public static byte[] decryptByPrivateKey(byte[] data, RSAPrivateKey privateKey) {
  try {
    Cipher cipher = Cipher.getInstance(KEY_ALGORITHM_PADDING);
    cipher.init(Cipher.DECRYPT_MODE, privateKey);
    //模长
    int key_len = privateKey.getModulus().bitLength() / 8;
    //如果密文长度大于模长则要分组解密
    return doFinal(cipher, data, key_len);
  } catch (Exception e) {
    LOGGER.error("decryptByPrivateKey ex", e);
    throw new CryptoException("RSA decrypt ex", e);
  }
}
origin: aa112901/remusic

/**
 * 私钥解密
 *
 * @param data
 * @param privateKey
 * @return
 * @throws Exception
 */
public static String decryptByPrivateKey(String data, RSAPrivateKey privateKey)
    throws Exception {
  Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");
  cipher.init(Cipher.DECRYPT_MODE, privateKey);
  //模长
  int key_len = privateKey.getModulus().bitLength() / 8;
  byte[] bytes = data.getBytes();
  byte[] bcd = ASCII_To_BCD(bytes, bytes.length);
  System.err.println(bcd.length);
  //如果密文长度大于模长则要分组解密
  String ming = "";
  byte[][] arrays = splitArray(bcd, key_len);
  for (byte[] arr : arrays) {
    ming += new String(cipher.doFinal(arr));
  }
  return ming;
}
origin: kaaproject/kaa

/**
 * Validates RSA public and private key.
 *
 * @param keyPair the keypair
 * @return true if keys matches
 */
public static boolean validateKeyPair(KeyPair keyPair) {
 RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
 RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
 if (publicKey.getModulus().bitLength() != privateKey.getModulus().bitLength()) {
  LOG.error("Keypair length matching error");
  return false;
 }
 byte[] rawPayload = new byte[64];
 new Random().nextBytes(rawPayload);
 MessageEncoderDecoder encDec = new MessageEncoderDecoder(privateKey, publicKey);
 byte[] encodedPayload;
 byte[] decodedPayload;
 try {
  encodedPayload = encDec.encodeData(rawPayload);
  decodedPayload = encDec.decodeData(encodedPayload);
 } catch (GeneralSecurityException ex) {
  LOG.error("Validation keypair error ", ex);
  return false;
 }
 return Arrays.equals(rawPayload, decodedPayload);
}
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: yinjihuan/spring-cloud

/**
 * 私钥解密
 * 
 * @param data
 * @param privateKey
 * @return
 * @throws Exception
 */
public static String decryptByPrivateKey(String data, RSAPrivateKey privateKey) throws Exception {
  Cipher cipher = Cipher.getInstance("RSA");
  cipher.init(Cipher.DECRYPT_MODE, privateKey);
  // 模长
  int key_len = privateKey.getModulus().bitLength() / 8;
  byte[] bytes = data.getBytes();
  byte[] bcd = ASCII_To_BCD(bytes, bytes.length);
  // 如果密文长度大于模长则要分组解密
  String ming = "";
  byte[][] arrays = splitArray(bcd, key_len);
  for (byte[] arr : arrays) {
    ming += new String(cipher.doFinal(arr));
  }
  return ming;
}
origin: yinjihuan/spring-cloud

/**
 * 私钥解密
 * 
 * @param data
 * @param privateKey
 * @return
 * @throws Exception
 */
public static String decryptByPrivateKey(String data) throws Exception {
  RSAPrivateKey privateKey = RSAUtils.getPrivateKey(modulus, private_exponent);
  Cipher cipher = Cipher.getInstance("RSA");
  cipher.init(Cipher.DECRYPT_MODE, privateKey);
  // 模长
  int key_len = privateKey.getModulus().bitLength() / 8;
  byte[] bytes = data.getBytes();
  byte[] bcd = ASCII_To_BCD(bytes, bytes.length);
  // 如果密文长度大于模长则要分组解密
  String ming = "";
  byte[][] arrays = splitArray(bcd, key_len);
  for (byte[] arr : arrays) {
    ming += new String(cipher.doFinal(arr));
  }
  return ming;
}
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: i2p/i2p.i2p

int sz = k.getModulus().bitLength();
SigType type;
if (sz <= ((RSAKeyGenParameterSpec) SigType.RSA_SHA256_2048.getParams()).getKeysize())
origin: i2p/i2p.i2p

RSAPrivateKey rsapriv = SigUtil.toJavaRSAKey(priv);
BigInteger exp = ((RSAKeyGenParameterSpec)type.getParams()).getPublicExponent();
RSAPublicKeySpec rsaks = new RSAPublicKeySpec(rsapriv.getModulus(), exp);
KeyFactory rsakf = KeyFactory.getInstance("RSA");
RSAPublicKey rsapub = (RSAPublicKey) rsakf.generatePublic(rsaks);
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: 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: org.wildfly.security/wildfly-elytron

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

RawRSAPrivateKey(final RSAPrivateKey original) {
  super(original);
  privateExponent = original.getPrivateExponent();
  modulus = original.getModulus();
}
origin: org.conscrypt/conscrypt-openjdk-uber

static OpenSSLKey wrapPlatformKey(RSAPrivateKey rsaPrivateKey)
    throws InvalidKeyException {
  OpenSSLKey wrapper = Platform.wrapRsaKey(rsaPrivateKey);
  if (wrapper != null) {
    return wrapper;
  }
  return new OpenSSLKey(NativeCrypto.getRSAPrivateKeyWrapper(rsaPrivateKey, rsaPrivateKey
      .getModulus().toByteArray()), true);
}
java.security.interfacesRSAPrivateKeygetModulus

Popular methods of RSAPrivateKey

  • getPrivateExponent
    Returns the private exponent d.
  • getEncoded
  • getFormat
  • <init>
  • getAlgorithm

Popular in Java

  • Creating JSON documents from java classes using gson
  • notifyDataSetChanged (ArrayAdapter)
  • setRequestProperty (URLConnection)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • InetAddress (java.net)
    This class represents an Internet Protocol (IP) address. An IP address is either a 32-bit or 128-bit
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • JPanel (javax.swing)
  • Option (scala)
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