Codota Logo
Key.getEncoded
Code IndexAdd Codota 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)

  • Common ways to obtain Key
private void myMethod () {
Key k =
  • Codota IconString algorithm;new SecretKeySpec(key, algorithm)
  • Codota IconKeyStore keyStore;String alias;String password;keyStore.getKey(alias, password.toCharArray())
  • Codota IconKeyStore ks;String alias;ks.getKey(alias, password)
  • Smart code suggestions by Codota
}
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_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: 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: 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 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();
 }
}
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();
 }
}
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

  • Creating JSON documents from java classes using gson
  • notifyDataSetChanged (ArrayAdapter)
  • getExternalFilesDir (Context)
  • getContentResolver (Context)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • String (java.lang)
  • Timer (java.util)
    A facility for threads to schedule tasks for future execution in a background thread. Tasks may be s
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Table (org.hibernate.mapping)
    A relational table
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
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