javax.crypto

How to export symmetric encryption key?

情到浓时终转凉″ 提交于 2021-02-18 08:41:11
问题 I'm trying to implement the javax.crypto encryption between my apps (through intnets). I follow this (accepted answer): https://stackoverflow.com/questions/4319496/how-to-encrypt-and-decrypt-data-in-java .The problem is as I understood I need to have the same SecretKeySpec key in both of my apps in order to encrypt/decrypt the data. I have no idea how to export it (as a String or anything) and then hardcode it in both of my apps. 回答1: You can export a SecretKey using the getEncoded() method.

iOS CryptoKit in Java

自古美人都是妖i 提交于 2020-02-28 09:43:06
问题 I am looking for settings/parameters of CryptoKit which will allow me to share data between iOS App and a Java Application. The flow would be something like below: - Use CryptoKit to encrypt a text using a fixed key and random initialization vector (IV). - In the Java application use standard javax libraries to perform the decryption using the same fixed key. The random IV will be transported/shared with the application along with the encrypted text. Similarly, the reverse is also required,

javax.crypto JDK source code, again

徘徊边缘 提交于 2019-12-07 07:53:30
问题 I've been looking for the javax.crypto JDK source code and I could not find it. Either this is due to my abject searching inability or there must be a reason why the code is not available (the JDK is supposed to be open source, right?) . My guess is that the current jdk javax.crypto has a NSA-mandated backdoor, making open-source release awkward. My questions are the following: Where is the jdk javax.crypto source code? If, as I believe, the jdk javax.crypto source code is not available, how

javax.crypto.Cipher equivalent code in Nodejs Crypto Javascript

烈酒焚心 提交于 2019-12-06 13:01:00
问题 I'm trying to convert below java code into nodejs. public static String encrypt(String accessToken) throws Exception { Cipher cipher = Cipher.getInstance("AES"); String merchantKey = "11111111111111111111"; String st = StringUtils.substring(merchantKey, 0, 16); System.out.println(st); Key secretKey = new SecretKeySpec(st.getBytes(), "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] encryptedByte = cipher.doFinal(accessToken.getBytes()); // convert the byte to hex format StringBuffer

javax.crypto JDK source code, again

本小妞迷上赌 提交于 2019-12-05 14:22:59
I've been looking for the javax.crypto JDK source code and I could not find it. Either this is due to my abject searching inability or there must be a reason why the code is not available (the JDK is supposed to be open source, right?) . My guess is that the current jdk javax.crypto has a NSA-mandated backdoor, making open-source release awkward. My questions are the following: Where is the jdk javax.crypto source code? If, as I believe, the jdk javax.crypto source code is not available, how can I check whether my fears that it contains a backdoor are justfied or not? See Where do I find the

Decrypt AES/CBC/PKCS5Padding with CryptoJS

為{幸葍}努か 提交于 2019-12-05 11:04:49
问题 I generate 128bit AES/CBC/PKCS5Padding key using Java javax.crypto API. Here is the algorithm that I use: public static String encryptAES(String data, String secretKey) { try { byte[] secretKeys = Hashing.sha1().hashString(secretKey, Charsets.UTF_8) .toString().substring(0, 16) .getBytes(Charsets.UTF_8); final SecretKey secret = new SecretKeySpec(secretKeys, "AES"); final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secret); final

Javascript/NodeJS equivalent code for the Java code Cipher.doFinal(byte[])?

夙愿已清 提交于 2019-12-05 06:09:58
问题 I am migrating some server-side Java code to a new NodeJS server. I am looking for an equivalent method call in Javascript to Java's Cipher.doFinal(byte[]) Note that I can't use NodeJS Buffers because they don't support negative Byte values. So to do my encryption, I'll need a method that accepts an array of positive and negative numbers. Here's all of what I currently have that is related to this problem: Node JS / Javascript: var crypto = require('crypto'); var cipher = crypto.createCipher(

javax.crypto.Cipher equivalent code in Nodejs Crypto Javascript

别来无恙 提交于 2019-12-04 19:10:09
I'm trying to convert below java code into nodejs. public static String encrypt(String accessToken) throws Exception { Cipher cipher = Cipher.getInstance("AES"); String merchantKey = "11111111111111111111"; String st = StringUtils.substring(merchantKey, 0, 16); System.out.println(st); Key secretKey = new SecretKeySpec(st.getBytes(), "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] encryptedByte = cipher.doFinal(accessToken.getBytes()); // convert the byte to hex format StringBuffer sb = new StringBuffer(); for (int i = 0; i < encryptedByte.length; i++) { sb.append(Integer.toString(

Encrypt using OpenSSL in the same way Java does

笑着哭i 提交于 2019-12-04 14:35:33
问题 I have to encrypt an string using bash script in the same way I encrypt using javax.crypto.Cipher. At java I use AES-256 with the key "0123456789". But When I use openssl I had to convert "0123456789" to hex, but the result is not the same of the java echo "lun01" | openssl aes-256-cbc -e -a -K 7573746f726530313233343536373839 -iv 7573746f726530313233343536373839 dpMyN7L5HI8VZEs1biQJ7g== Java: public class CryptUtil { public static final String DEFAULT_KEY = "0123456789"; private static

Decrypt AES/CBC/PKCS5Padding with CryptoJS

江枫思渺然 提交于 2019-12-03 21:54:13
I generate 128bit AES/CBC/PKCS5Padding key using Java javax.crypto API. Here is the algorithm that I use: public static String encryptAES(String data, String secretKey) { try { byte[] secretKeys = Hashing.sha1().hashString(secretKey, Charsets.UTF_8) .toString().substring(0, 16) .getBytes(Charsets.UTF_8); final SecretKey secret = new SecretKeySpec(secretKeys, "AES"); final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secret); final AlgorithmParameters params = cipher.getParameters(); final byte[] iv = params.getParameterSpec(IvParameterSpec.class)