Tabnine Logo
Key.getEncoded
Code IndexAdd Tabnine to your IDE (free)

How to use
getEncoded
method
in
java.security.Key

Best Java code snippets using java.security.Key.getEncoded (Showing top 20 results out of 2,943)

origin: apache/hbase

public byte[] getKeyBytes() {
 return key.getEncoded();
}
origin: jenkinsci/jenkins

public void writeKey(Key key) throws IOException {
  writeUTF(new String(Base64.encodeBase64(key.getEncoded())));
}
origin: apache/incubator-gobblin

@Override
public byte[] getEncodedKey(String id) {
 try {
  Key k = ks.getKey(id, password);
  return (k == null) ? null : k.getEncoded();
 } catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException e) {
  log.warn("Error trying to decode key " + id, e);
  return null;
 }
}
origin: wildfly/wildfly

/** Encrypts the current secret key with the requester's public key (the requester will decrypt it with its private key) */
protected byte[] encryptSecretKey(Key secret_key, PublicKey public_key) throws Exception {
  Cipher tmp;
  if (provider != null && !provider.trim().isEmpty())
    tmp=Cipher.getInstance(asym_algorithm, provider);
  else
    tmp=Cipher.getInstance(asym_algorithm);
  tmp.init(Cipher.ENCRYPT_MODE, public_key);
  // encrypt current secret key
  return tmp.doFinal(secret_key.getEncoded());
}
origin: mpusher/mpush

/**
 * 编码密钥,便于存储
 *
 * @param key 密钥
 * @return base64后的字符串
 * @throws Exception Exception
 */
public static String encodeBase64(Key key) throws Exception {
  return Base64Utils.encode(key.getEncoded());
}
origin: apache/ignite

/** {@inheritDoc} */
@Override public byte[] masterKeyDigest() {
  ensureStarted();
  return makeDigest(masterKey.key().getEncoded());
}
origin: wildfly/wildfly

RawKey(Key original) {
  algorithm = original.getAlgorithm();
  format = original.getFormat();
  final byte[] encoded = original.getEncoded();
  this.encoded = encoded == null ? null : encoded.clone();
}
origin: jamesdbloom/mockserver

private static SubjectKeyIdentifier createSubjectKeyIdentifier(Key key) throws IOException {
  try (ASN1InputStream is = new ASN1InputStream(new ByteArrayInputStream(key.getEncoded()))) {
    ASN1Sequence seq = (ASN1Sequence) is.readObject();
    SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(seq);
    return new BcX509ExtensionUtils().createSubjectKeyIdentifier(info);
  }
}
origin: apache/hbase

 public Context setKey(Key key) {
  Preconditions.checkNotNull(cipher, "Context does not have a cipher");
  // validate the key length
  byte[] encoded = key.getEncoded();
  if (encoded.length != cipher.getKeyLength()) {
   throw new RuntimeException("Illegal key length, have=" + encoded.length +
    ", want=" + cipher.getKeyLength());
  }
  this.key = key;
  this.keyHash = MD5Hash.getMD5AsHex(encoded);
  return this;
 }
}
origin: apache/ignite

/** {@inheritDoc} */
@Override public KeystoreEncryptionKey decryptKey(byte[] data) {
  byte[] serKey = decrypt(data, masterKey);
  KeystoreEncryptionKey key = U.fromBytes(serKey);
  byte[] digest = makeDigest(key.key().getEncoded());
  if (!Arrays.equals(key.digest, digest))
    throw new IgniteException("Key is broken!");
  return key;
}
origin: apache/shiro

/**
 * Default constructor that initializes a {@link DefaultSerializer} as the {@link #getSerializer() serializer} and
 * an {@link AesCipherService} as the {@link #getCipherService() cipherService}.
 */
public AbstractRememberMeManager() {
  this.serializer = new DefaultSerializer<PrincipalCollection>();
  AesCipherService cipherService = new AesCipherService();
  this.cipherService = cipherService;
  setCipherKey(cipherService.generateNewKey().getEncoded());
}
origin: SonarSource/sonarqube

@Test
public void loadSecretKeyFromFile_trim_content() throws Exception {
 URL resource = getClass().getResource("/org/sonar/api/config/AesCipherTest/non_trimmed_secret_key.txt");
 String path = new File(resource.toURI()).getCanonicalPath();
 AesCipher cipher = new AesCipher(null);
 Key secretKey = cipher.loadSecretFileFromFile(path);
 assertThat(secretKey.getAlgorithm()).isEqualTo("AES");
 assertThat(secretKey.getEncoded().length).isGreaterThan(10);
}
origin: SonarSource/sonarqube

@Test
public void loadSecretKeyFromFile() throws Exception {
 AesCipher cipher = new AesCipher(null);
 Key secretKey = cipher.loadSecretFileFromFile(pathToSecretKey());
 assertThat(secretKey.getAlgorithm()).isEqualTo("AES");
 assertThat(secretKey.getEncoded().length).isGreaterThan(10);
}
origin: SonarSource/sonarqube

@Test
public void loadSecretKeyFromFile() throws Exception {
 AesCipher cipher = new AesCipher(null);
 Key secretKey = cipher.loadSecretFileFromFile(pathToSecretKey());
 assertThat(secretKey.getAlgorithm()).isEqualTo("AES");
 assertThat(secretKey.getEncoded().length).isGreaterThan(10);
}
origin: SonarSource/sonarqube

@Test
public void loadSecretKeyFromFile_trim_content() throws Exception {
 String path = getPath("non_trimmed_secret_key.txt");
 AesCipher cipher = new AesCipher(null);
 Key secretKey = cipher.loadSecretFileFromFile(path);
 assertThat(secretKey.getAlgorithm()).isEqualTo("AES");
 assertThat(secretKey.getEncoded().length).isGreaterThan(10);
}
origin: apache/hbase

 @Test
 public void testKeyStoreKeyProviderWithPasswordFile() throws Exception {
  KeyProvider provider = new KeyStoreKeyProvider();
  provider.init("jceks://" + storeFile.toURI().getPath() + "?passwordFile=" +
   URLEncoder.encode(passwordFile.getAbsolutePath(), "UTF-8"));
  Key key = provider.getKey(ALIAS);
  assertNotNull(key);
  byte[] keyBytes = key.getEncoded();
  assertEquals(keyBytes.length, KEY.length);
  for (int i = 0; i < KEY.length; i++) {
   assertEquals(keyBytes[i], KEY[i]);
  }
 }
}
origin: apache/hbase

@Test
public void testKeyStoreKeyProviderWithPassword() throws Exception {
 KeyProvider provider = new KeyStoreKeyProvider();
 provider.init("jceks://" + storeFile.toURI().getPath() + "?password=" + PASSWORD);
 Key key = provider.getKey(ALIAS);
 assertNotNull(key);
 byte[] keyBytes = key.getEncoded();
 assertEquals(keyBytes.length, KEY.length);
 for (int i = 0; i < KEY.length; i++) {
  assertEquals(keyBytes[i], KEY[i]);
 }
}
origin: apache/hbase

@Test
public void testTestProvider() {
 Configuration conf = HBaseConfiguration.create();
 conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
 KeyProvider provider = Encryption.getKeyProvider(conf);
 assertNotNull("Null returned for provider", provider);
 assertTrue("Provider is not the expected type", provider instanceof KeyProviderForTesting);
 Key key = provider.getKey("foo");
 assertNotNull("Test provider did not return a key as expected", key);
 assertEquals("Test provider did not create a key for AES", "AES", key.getAlgorithm());
 assertEquals("Test provider did not create a key of adequate length", AES.KEY_LENGTH,
  key.getEncoded().length);
}
origin: apache/hbase

private byte[] extractHFileKey(Path path) throws Exception {
 HFile.Reader reader = HFile.createReader(TEST_UTIL.getTestFileSystem(), path,
  new CacheConfig(conf), true, conf);
 try {
  reader.loadFileInfo();
  Encryption.Context cryptoContext = reader.getFileContext().getEncryptionContext();
  assertNotNull("Reader has a null crypto context", cryptoContext);
  Key key = cryptoContext.getKey();
  assertNotNull("Crypto context has no key", key);
  return key.getEncoded();
 } finally {
  reader.close();
 }
}
origin: apache/hbase

private static byte[] extractHFileKey(Path path) throws Exception {
 HFile.Reader reader = HFile.createReader(TEST_UTIL.getTestFileSystem(), path,
  new CacheConfig(conf), true, conf);
 try {
  reader.loadFileInfo();
  Encryption.Context cryptoContext = reader.getFileContext().getEncryptionContext();
  assertNotNull("Reader has a null crypto context", cryptoContext);
  Key key = cryptoContext.getKey();
  assertNotNull("Crypto context has no key", key);
  return key.getEncoded();
 } finally {
  reader.close();
 }
}
java.securityKeygetEncoded

Javadoc

Returns the encoded form of this key, or null if encoding is not supported by this key.

Popular methods of Key

  • getAlgorithm
    Returns the standard algorithm name for this key. For example, "DSA" would indicate that this key is
  • getFormat
    Returns the name of the primary encoding format of this key, or null if this key does not support en
  • <init>

Popular in Java

  • Updating database using SQL prepared statement
  • getSupportFragmentManager (FragmentActivity)
  • getSharedPreferences (Context)
  • getExternalFilesDir (Context)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • JFrame (javax.swing)
  • Top Sublime Text plugins
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