Tag: 加密

使用java在客户端解密

我在服务器端加密了会话ID,但是当我尝试在客户端解密会话ID时,会出现一些错误。 请任何人都可以帮助解决错误。 public static String decrypt(String sessionId) { try { Cipher cipher = Cipher.getInstance(“AES/ECB/PKCS5PADDING”); final SecretKeySpec secretKey = new SecretKeySpec(key, “AES”); cipher.init(Cipher.DECRYPT_MODE, secretKey); final String decryptedSessionId = new String(cipher.doFinal(Base64.decodeBase64(sessionId))); return decryptedSessionId; } catch (Exception e) { e.printStackTrace(); } return null; } 即将发生的错误是:JRE仿真库中不存在类’javax.crypto.Cipher’,因此它不能用于“某些”GWT模块的客户端代码中。 此检查报告JDK类的客户端代码中的用法,这在JRE仿真库中不存在。 我使用的加密方法是: public static String encrypt(String sessionId) { try { Cipher cipher = […]

iOS对称密钥加密/解密等同于Java

我试图加密/解密数据ios到java和java到ios但我在java中加密的数据没有在ios中正确解密,在ios中加密的数据在java中没有正确解密 – (NSData *) encrypt:(NSData *) dataToEncrypt symmetricKey:(NSData *)symmetricKey context:(CCOperation)encryptOrDecrypt{ NSUInteger data_length= [dataToEncrypt length]; uint8_t input_raw_data[data_length]; //The [dataToEncrypt length] gives the number of chars present in the string.So say there are 10 chars. //Now,the getBytes needs to get the raw bytes from this ie binary NSData.But suppose the encoding was //full 16 bit encoding then […]

DESFire认证解密

我目前正在使用DESFire EV1非接触式卡。 我正在尝试使用主密钥“00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00”解密DES / CBC加密的random_b。 我正在使用此代码: byte[] encipheredCodeRandomB = { (byte)0xEA ,(byte)0x18 ,(byte)0xDE ,(byte)0xFF ,(byte)0x52 ,(byte)0x0E,(byte)0xCD, (byte) 90}; byte[] masterKeyBytes = “0000000000000000”.getBytes(); byte[] ivBytes = “00000000”.getBytes(); DESKeySpec desKeySpec = new DESKeySpec(masterKeyBytes); SecretKeyFactory desKeyFact = SecretKeyFactory.getInstance(“DES”); SecretKey s = desKeyFact.generateSecret(desKeySpec); aliceCipher […]

java加密方法等效于节点js crypto

我有java加密function代码 public String encrypt(String Data, String keySet) throws Exception { byte[] keyByte = keySet.getBytes(); Key key = generateKey(keyByte); Cipher c = Cipher.getInstance(“AES”); c.init(Cipher.ENCRYPT_MODE, key); //2 byte[] encVal = c.doFinal(Data.getBytes()); //1 byte[] encryptedByteValue = new Base64().encode(encVal); //3 String encryptedValue = new String(encryptedByteValue); //4 return encryptedValue; } private static Key generateKey(byte[] keyByte) throws Exception { Key key […]

从java中的图像中读取加密的字节

我必须在加密图像(Stegnography)中嵌入文本。 我用Google搜索并找到了在图片中嵌入文字的代码。 但我必须首先加密图像并在此加密图像中嵌入文本。 我的尝试如下。 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package tbn; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Transparency; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.ComponentColorModel; import java.awt.image.DataBuffer; import java.awt.image.DataBufferByte; import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.io.File; import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; […]

从保管箱解密图像并显示

我想解密照片,它将在我的三星Galaxy选项卡上显示它,我尝试了ByteArrayOutputStream,当我在我的模拟器中运行它时,当我从dropbox中随机下载照片时,它会显示内部错误。 这是为什么这样的? 或者我从保管箱调用了错误的路径? 有人帮我解决这个问题吗? 因为我已经尝试了很多方法来解决它但我仍然无法解决问题.. // Now pick a random one int index = (int)(Math.random() * thumbs.size()); Entry ent = thumbs.get(index); String path = ent.path; mFileLen = ent.bytes; String cachePath = mContext.getCacheDir().getAbsolutePath() + “/” + IMAGE_FILE_NAME; try { KeyGenerator keygen = KeyGenerator.getInstance(“DES”); SecretKey key = keygen.generateKey(); //generate key byte[] encryptedData; byte[] decryptedData; Cipher cipher = […]

解密Python中用3DES加密的数据

我正在尝试使用PyCrypto解密数据。 数据使用javax.crypto包以Java编码。 加密是Triple DES(在Java中称为“ DESede ”)。 据我所知,默认设置用于一切。 但是,当我在Python中解密数据时,数据总是存在问题。 这是加密/解密的Java代码: import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESedeKeySpec; import java.security.spec.KeySpec; public final class Encrypter { public static final String DESEDE_ENCRYPTION = “DESede”; private KeySpec keySpec; private SecretKeyFactory keyFactory; private Cipher cipher; private static final String UNICODE_FORMAT = “UTF8”; public Encrypter(String encryptionKey) throws […]

文件加密Java

我正在制作一个包含一些数据的系统,我希望它采用这种数据(XML格式)并将其保存为txt文件中的加密字符串,稍后当软件再次打开时,解密文件并正常阅读。 我已经拥有将xml转换为字符串的所有代码,我已经有了保存它的代码,我只需要一些加密/解密代码的帮助? 注意:我确实找到了一些加密/解密的代码,但似乎我无法将代码拆分为2种方法。 这是我的尝试: public class AesEncrDec { public static String encrypt(String Data) { byte[] byteCipherText = null; try { String plainData=Data,cipherText,decryptedText; KeyGenerator keyGen = KeyGenerator.getInstance(“AES”); keyGen.init(128); SecureRandom rnd = new SecureRandom(); SecretKey secretKey = keyGen.generateKey(); IvParameterSpec iv; iv = new IvParameterSpec(rnd.generateSeed(16)); Cipher aesCipher = Cipher.getInstance(“AES”); aesCipher.init(Cipher.ENCRYPT_MODE,secretKey,iv); byte[] byteDataToEncrypt = plainData.getBytes(); byteCipherText = aesCipher.doFinal(byteDataToEncrypt); cipherText […]

将加密的图像字节保存到文件并恢复到java中的原始图像

我有一个图像加密和解密的问题,原因现在已经确定,但我无法找到解决方案。 我正在尝试实施这个项目 但问题是加密后的图像字节在使用rasterclass和ImageIO类写入图像文件后无法恢复 我的问题,尝试过的代码和解释都在这里提交 我必须在加密图像(Stegnography)中嵌入文本。 我用Google搜索并找到了在图片中嵌入文字的代码。 但我必须首先加密图像并在此加密图像中嵌入文本。 我的尝试如下。 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package tbn; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Transparency; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.ComponentColorModel; import java.awt.image.DataBuffer; import java.awt.image.DataBufferByte; import java.awt.image.Raster; import java.awt.image.WritableRaster; import java.io.File; import java.io.IOException; import java.security.InvalidKeyException; […]

使用3DES加密字符串时出现NoSuchProviderException

我是Java新手。 我遵循本教程使用3DES算法进行加密和解密。 我这样实现了: 创建了一个类并放置了上面链接中提供的3DES代码。 在上面的链接中调用加密方法如下: String encryptedPassword = Encrypter.encrypt(edtText.getText().toString()); 我在logcat中得到exception,如下所示: 05-02 15:19:10.804: W/System.err(4445): java.security.NoSuchProviderException: Provider not available: SunJCE 05-02 15:19:10.820: W/System.err(4445): at javax.crypto.Cipher.getInstance(Cipher.java:209) 05-02 15:19:10.820: W/System.err(4445): at com.example.utilities.Encrypter.encrypt(Encrypter.java:46) 05-02 15:19:10.820: W/System.err(4445): at com.example.screens.RegisterScreen.onClick(RegisterScreen.java:152) 05-02 15:19:10.820: W/System.err(4445): at android.view.View.performClick(View.java:2485) 05-02 15:19:10.820: W/System.err(4445): at android.view.View$PerformClick.run(View.java:9080) 05-02 15:19:10.828: W/System.err(4445): at android.os.Handler.handleCallback(Handler.java:587) 05-02 15:19:10.828: W/System.err(4445): at android.os.Handler.dispatchMessage(Handler.java:92) 05-02 15:19:10.828: […]