use of javax.crypto.spec.SecretKeySpec in project c-geo by just-radovan.
the class cgBase method hashHmac.
public static byte[] hashHmac(String text, String salt) {
byte[] macBytes = {};
try {
SecretKeySpec secretKeySpec = new SecretKeySpec(salt.getBytes(), "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(secretKeySpec);
macBytes = mac.doFinal(text.getBytes());
} catch (Exception e) {
Log.e(cgSettings.tag, "cgBase.hashHmac: " + e.toString());
}
return macBytes;
}
use of javax.crypto.spec.SecretKeySpec in project hbase by apache.
the class TestHBaseFsckEncryption method setUp.
@Before
public void setUp() throws Exception {
conf = TEST_UTIL.getConfiguration();
conf.setInt("hfile.format.version", 3);
conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
conf.set(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, "hbase");
// Create the test encryption key
SecureRandom rng = new SecureRandom();
byte[] keyBytes = new byte[AES.KEY_LENGTH];
rng.nextBytes(keyBytes);
String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
cfKey = new SecretKeySpec(keyBytes, algorithm);
// Start the minicluster
TEST_UTIL.startMiniCluster(3);
// Create the table
htd = new HTableDescriptor(TableName.valueOf("default", "TestHBaseFsckEncryption"));
HColumnDescriptor hcd = new HColumnDescriptor("cf");
hcd.setEncryptionType(algorithm);
hcd.setEncryptionKey(EncryptionUtil.wrapKey(conf, conf.get(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, User.getCurrent().getShortName()), cfKey));
htd.addFamily(hcd);
TEST_UTIL.getAdmin().createTable(htd);
TEST_UTIL.waitTableAvailable(htd.getName(), 5000);
}
use of javax.crypto.spec.SecretKeySpec in project openhab1-addons by openhab.
the class KM200Comm method encodeMessage.
/**
* This function does the encoding for a new message to the device
*
*/
public byte[] encodeMessage(String data) {
byte[] encryptedDataB64 = null;
try {
// --- create cipher
byte[] bdata = data.getBytes(device.getCharSet());
final Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(device.getCryptKeyPriv(), "AES"));
logger.debug("Create padding..");
int bsize = cipher.getBlockSize();
logger.debug("Add Padding and Encrypt AES..");
final byte[] encryptedData = cipher.doFinal(addZeroPadding(bdata, bsize, device.getCharSet()));
logger.debug("Encrypt B64..");
try {
encryptedDataB64 = Base64.encodeBase64(encryptedData);
} catch (Exception e) {
logger.error("Base64encoding not possible: {}", e.getMessage());
}
return encryptedDataB64;
} catch (UnsupportedEncodingException | GeneralSecurityException e) {
// failure to authenticate
logger.error("Exception on encoding: {}", e);
return null;
}
}
use of javax.crypto.spec.SecretKeySpec in project OpenAM by OpenRock.
the class CreateSoapSTSDeployment method setAgentPasswordEncryptionKeyEntry.
private void setAgentPasswordEncryptionKeyEntry(KeyStore soapSTSKeystore, char[] keystorePassword, String agentPasswordEncryptionKey) throws KeyStoreException {
//the keystore password will also protected the password encryption key
KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection(keystorePassword);
SecretKey agentPasswordEncryptionSecretKey = new SecretKeySpec(agentPasswordEncryptionKey.getBytes(StandardCharsets.US_ASCII), SECRET_KEY_ALGORITHM_TYPE);
KeyStore.SecretKeyEntry secretKeyEntry = new KeyStore.SecretKeyEntry(agentPasswordEncryptionSecretKey);
soapSTSKeystore.setEntry(SharedSTSConstants.AM_INTERNAL_PEK_ALIAS, secretKeyEntry, protParam);
}
use of javax.crypto.spec.SecretKeySpec in project XobotOS by xamarin.
the class JCEKeyGenerator method engineGenerateKey.
protected SecretKey engineGenerateKey() {
if (uninitialised) {
engine.init(new KeyGenerationParameters(new SecureRandom(), defaultKeySize));
uninitialised = false;
}
return new SecretKeySpec(engine.generateKey(), algName);
}
Aggregations