Codota Logo
RSAPublicKey.getPublicExponent
Code IndexAdd Codota to your IDE (free)

How to use
getPublicExponent
method
in
java.security.interfaces.RSAPublicKey

Best Java code snippets using java.security.interfaces.RSAPublicKey.getPublicExponent (Showing top 20 results out of 1,341)

Refine searchRefine arrow

  • RSAPublicKey.getModulus
  • Common ways to obtain RSAPublicKey
private void myMethod () {
RSAPublicKey r =
  • Codota IconKeyPair keyPair;(RSAPublicKey) keyPair.getPublic()
  • Codota IconKeyFactory keyFactory;KeySpec keySpec;(RSAPublicKey) keyFactory.generatePublic(keySpec)
  • Codota IconX509Certificate x509Certificate;(RSAPublicKey) x509Certificate.getPublicKey()
  • Smart code suggestions by Codota
}
origin: alibaba/druid

public static String decrypt(PublicKey publicKey, String cipherText)
    throws Exception {
  Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
  try {
    cipher.init(Cipher.DECRYPT_MODE, publicKey);
  } catch (InvalidKeyException e) {
    // 因为 IBM JDK 不支持私钥加密, 公钥解密, 所以要反转公私钥
    // 也就是说对于解密, 可以通过公钥的参数伪造一个私钥对象欺骗 IBM JDK
    RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
    RSAPrivateKeySpec spec = new RSAPrivateKeySpec(rsaPublicKey.getModulus(), rsaPublicKey.getPublicExponent());
    Key fakePrivateKey = KeyFactory.getInstance("RSA").generatePrivate(spec);
    cipher = Cipher.getInstance("RSA"); //It is a stateful object. so we need to get new one.
    cipher.init(Cipher.DECRYPT_MODE, fakePrivateKey);
  }
  
  if (cipherText == null || cipherText.length() == 0) {
    return cipherText;
  }
  byte[] cipherBytes = Base64.base64ToByteArray(cipherText);
  byte[] plainBytes = cipher.doFinal(cipherBytes);
  return new String(plainBytes);
}
origin: skylot/jadx

String generateRSAPublicKey() {
  RSAPublicKey pub = (RSAPublicKey) cert.getPublicKey();
  StringBuilder builder = new StringBuilder();
  append(builder, NLS.str("certificate.serialPubKeyType"), pub.getAlgorithm());
  append(builder, NLS.str("certificate.serialPubKeyExponent"), pub.getPublicExponent().toString(10));
  append(builder, NLS.str("certificate.serialPubKeyModulusSize"), Integer.toString(
      pub.getModulus().toString(2).length()));
  append(builder, NLS.str("certificate.serialPubKeyModulus"), pub.getModulus().toString(10));
  return builder.toString();
}
origin: hierynomus/sshj

@Override
protected void writePubKeyContentsIntoBuffer(PublicKey pk, Buffer<?> buf) {
  final RSAPublicKey rsaKey = (RSAPublicKey) pk;
  buf.putMPInt(rsaKey.getPublicExponent()) // e
    .putMPInt(rsaKey.getModulus()); // n
}
origin: aa112901/remusic

String modulus = publicKey.getModulus().toString();
String public_exponent = publicKey.getPublicExponent().toString();
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: cloudfoundry/uaa

@Override
public Map<String, Object> getJwkMap() {
  Map<String, Object> result = new HashMap<>();
  result.put("alg", this.algorithm());
  result.put("value", this.verifierKey);
  //new values per OpenID and JWK spec
  result.put("use", JsonWebKey.KeyUse.sig.name());
  result.put("kid", this.keyId);
  result.put("kty", RSA.name());
  RSAPublicKey rsaKey = (RSAPublicKey) parseKeyPair(verifierKey).getPublic();
  if (rsaKey != null) {
    java.util.Base64.Encoder encoder = java.util.Base64.getUrlEncoder().withoutPadding();
    String n = encoder.encodeToString(rsaKey.getModulus().toByteArray());
    String e = encoder.encodeToString(rsaKey.getPublicExponent().toByteArray());
    result.put("n", n);
    result.put("e", e);
  }
  return result;
}
origin: kingthy/TVRemoteIME

n = pubkey.getModulus();
r = BigInteger.ZERO.setBit(KEY_LENGTH_WORDS * 32);
rr = r.modPow(BigInteger.valueOf(2), n);
  bbuf.putInt(i);
bbuf.putInt(pubkey.getPublicExponent().intValue());
return bbuf.array();
origin: wildfly/wildfly

static JsonObject getJwk(PublicKey publicKey, String algHeader) {
  if (publicKey instanceof RSAPublicKey) {
    RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
    return Json.createObjectBuilder()
        .add(EXPONENT, base64UrlEncode(rsaPublicKey.getPublicExponent().toByteArray()))
        .add(KEY_TYPE, "RSA")
        .add(MODULUS, base64UrlEncode(modulusToByteArray(rsaPublicKey.getModulus())))
        .build();
  } else if (publicKey instanceof ECPublicKey) {
    ECPublicKey ecPublicKey = (ECPublicKey) publicKey;
    int fieldSize = ecPublicKey.getParams().getCurve().getField().getFieldSize();
    return Json.createObjectBuilder()
        .add(CURVE, getCurveParameterFromAlgHeader(algHeader))
        .add(KEY_TYPE, "EC")
        .add(X_COORDINATE, base64UrlEncode(coordinateToByteArray(fieldSize, ecPublicKey.getW().getAffineX())))
        .add(Y_COORDINATE, base64UrlEncode(coordinateToByteArray(fieldSize, ecPublicKey.getW().getAffineY())))
        .build();
  } else {
    throw acme.unsupportedAcmeAccountPublicKeyType(publicKey.getAlgorithm());
  }
}
origin: cloudfoundry/uaa

@Test
public void create_key_from_pem_string() {
  KeyInfo keyInfo = KeyInfoBuilder.build("id", sampleRsaPrivateKey, ISSUER);
  assertEquals("RSA", keyInfo.type());
  assertNotNull(keyInfo.getVerifier());
  JsonWebKey key = new JsonWebKey(KeyInfoBuilder.build("id", sampleRsaPrivateKey, ISSUER).getJwkMap()).setKid("id");
  assertEquals(RSA, key.getKty());
  assertEquals("RSA", key.getKeyProperties().get("kty"));
  assertEquals("id", key.getKid());
  assertEquals(sig, key.getUse());
  assertEquals("sig", key.getKeyProperties().get("use"));
  assertNotNull(key.getValue());
  PublicKey pk = parseKeyPair(keyInfo.verifierKey()).getPublic();
  BigInteger exponent = ((RSAPublicKey) pk).getPublicExponent();
  BigInteger modulus = ((RSAPublicKey) pk).getModulus();
  java.util.Base64.Encoder encoder = java.util.Base64.getUrlEncoder().withoutPadding();
  assertEquals(encoder.encodeToString(exponent.toByteArray()), key.getKeyProperties().get("e"));
  assertEquals(encoder.encodeToString(modulus.toByteArray()), key.getKeyProperties().get("n"));
}
origin: cloudfoundry/uaa

@Test
public void create_key_from_public_pem_string() {
  KeyInfo keyInfo = KeyInfoBuilder.build("id", sampleRsaPrivateKey, ISSUER);
  assertEquals("RSA", keyInfo.type());
  assertNotNull(keyInfo.getVerifier());
  Map<String, Object> jwkMap = keyInfo.getJwkMap();
  JsonWebKey jsonWebKey = new JsonWebKey(jwkMap);
  JsonWebKey key = jsonWebKey.setKid("id");
  assertEquals(RSA, key.getKty());
  assertEquals("RSA", key.getKeyProperties().get("kty"));
  assertEquals("id", key.getKid());
  assertEquals(sig, key.getUse());
  assertEquals("sig", key.getKeyProperties().get("use"));
  assertNotNull(key.getValue());
  PublicKey pk = parseKeyPair(keyInfo.verifierKey()).getPublic();
  BigInteger exponent = ((RSAPublicKey) pk).getPublicExponent();
  BigInteger modulus = ((RSAPublicKey) pk).getModulus();
  java.util.Base64.Encoder encoder = java.util.Base64.getUrlEncoder().withoutPadding();
  assertEquals(encoder.encodeToString(exponent.toByteArray()), key.getKeyProperties().get("e"));
  assertEquals(encoder.encodeToString(modulus.toByteArray()), key.getKeyProperties().get("n"));
}
origin: com.alibaba/druid

public static String decrypt(PublicKey publicKey, String cipherText)
    throws Exception {
  Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
  try {
    cipher.init(Cipher.DECRYPT_MODE, publicKey);
  } catch (InvalidKeyException e) {
    // 因为 IBM JDK 不支持私钥加密, 公钥解密, 所以要反转公私钥
    // 也就是说对于解密, 可以通过公钥的参数伪造一个私钥对象欺骗 IBM JDK
    RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
    RSAPrivateKeySpec spec = new RSAPrivateKeySpec(rsaPublicKey.getModulus(), rsaPublicKey.getPublicExponent());
    Key fakePrivateKey = KeyFactory.getInstance("RSA").generatePrivate(spec);
    cipher = Cipher.getInstance("RSA"); //It is a stateful object. so we need to get new one.
    cipher.init(Cipher.DECRYPT_MODE, fakePrivateKey);
  }
  
  if (cipherText == null || cipherText.length() == 0) {
    return cipherText;
  }
  byte[] cipherBytes = Base64.base64ToByteArray(cipherText);
  byte[] plainBytes = cipher.doFinal(cipherBytes);
  return new String(plainBytes);
}
origin: resteasy/Resteasy

/**
* Encrypts the specified Content Encryption Key (CEK).
*
* @param pub The public RSA key. Must not be {@code null}.
* @param cek The Content Encryption Key (CEK) to encrypt. Must not be
*            {@code null}.
*
* @return The encrypted Content Encryption Key (CEK).
*
* @throws RuntimeException If encryption failed.
*/
public static byte[] encryptCEK(final RSAPublicKey pub, final SecretKey cek)
 throws RuntimeException {
 try {
   AsymmetricBlockCipher engine = new RSAEngine();
   // JCA identifier RSA/ECB/OAEPWithSHA-1AndMGF1Padding ?
   OAEPEncoding cipher = new OAEPEncoding(engine);
   BigInteger mod = pub.getModulus();
   BigInteger exp = pub.getPublicExponent();
   RSAKeyParameters keyParams = new RSAKeyParameters(false, mod, exp);
   cipher.init(true, keyParams);
   int inputBlockSize = cipher.getInputBlockSize();
   int outputBlockSize = cipher.getOutputBlockSize();
   byte[] keyBytes = cek.getEncoded();
   return cipher.processBlock(keyBytes, 0, keyBytes.length);
 } catch (Exception e) {
   // org.bouncycastle.crypto.InvalidCipherTextException
   throw new RuntimeException(Messages.MESSAGES.couldntEncryptCEK(e.getLocalizedMessage()), e);
 }
}
origin: ibinti/bugvm

JCERSAPublicKey(
  RSAPublicKey key)
{
  this.modulus = key.getModulus();
  this.publicExponent = key.getPublicExponent();
}
origin: ibinti/bugvm

BCRSAPublicKey(
  RSAPublicKey key)
{
  this.modulus = key.getModulus();
  this.publicExponent = key.getPublicExponent();
}
origin: BiglySoftware/BiglyBT

JCERSAPublicKey(
  RSAPublicKey key)
{
  this.modulus = key.getModulus();
  this.publicExponent = key.getPublicExponent();
}
origin: com.madgag.spongycastle/prov

JCERSAPublicKey(
  RSAPublicKey key)
{
  this.modulus = key.getModulus();
  this.publicExponent = key.getPublicExponent();
}
origin: org.apache.sshd/sshd-common

public static boolean compareRSAKeys(RSAPublicKey k1, RSAPublicKey k2) {
  if (Objects.equals(k1, k2)) {
    return true;
  } else if (k1 == null || k2 == null) {
    return false;   // both null is covered by Objects#equals
  } else {
    return Objects.equals(k1.getPublicExponent(), k2.getPublicExponent())
      && Objects.equals(k1.getModulus(), k2.getModulus());
  }
}
origin: org.xbib/sshd-common

public static boolean compareRSAKeys(RSAPublicKey k1, RSAPublicKey k2) {
  if (Objects.equals(k1, k2)) {
    return true;
  } else if (k1 == null || k2 == null) {
    return false;   // both null is covered by Objects#equals
  } else {
    return Objects.equals(k1.getPublicExponent(), k2.getPublicExponent())
        && Objects.equals(k1.getModulus(), k2.getModulus());
  }
}
origin: ibinti/bugvm

static RSAKeyParameters generatePublicKeyParameter(
  RSAPublicKey key)
{
  return new RSAKeyParameters(false, key.getModulus(), key.getPublicExponent());
}
origin: BiglySoftware/BiglyBT

static public RSAKeyParameters generatePublicKeyParameter(
  RSAPublicKey    key)
{
  return new RSAKeyParameters(false, key.getModulus(), key.getPublicExponent());
}
java.security.interfacesRSAPublicKeygetPublicExponent

Javadoc

Returns the public exponent e.

Popular methods of RSAPublicKey

  • getModulus
  • getEncoded
  • getAlgorithm
  • <init>

Popular in Java

  • Finding current android device location
  • addToBackStack (FragmentTransaction)
  • getExternalFilesDir (Context)
  • onCreateOptionsMenu (Activity)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Properties (java.util)
    The Properties class represents a persistent set of properties. The Properties can be saved to a st
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Collectors (java.util.stream)
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