aes

使用delphi+intraweb进行微信开发4—微信消息加解密

穿精又带淫゛_ 提交于 2019-11-30 07:43:50
在 上一讲 当中我做了个简单的微信文本消息回显应用,当时是以微信明文方式实现的,其实微信推荐的是消息应该加密传输以增加安全性,所以这讲说说微信消息的加解密。 在微信的 帮助页面 上可以下载微信消息加解密的例程,可惜的是没有Delphi语言的示例,网上搜索一番,没有人贡献出写好的Delphi版的微信加解密算法单元,好在有官方示例的C#版的,那就按照C#的改一个吧。 微信消息是以AES算法进行的加密处理,而遗憾的是Delphi并没有内置的AES算法单元,必须找第三方实现的,不过一般第三方实现的算法都因为种种原因并不完善,需要使用者酌情修改,所以在基础算法支持上Delphi确实和.net以及java这类的开发语言比不了。 呵呵,上网找Delphi版AES算法吧。在在这里要感谢 cnpack开发组 ,他们不但推出一流的delphi开发环境增强组件还有开源组件包cnvcl,这个组件包中有SHA1、AES、MD5等多种算法单元,我打开AES算法单元查看,发现封装的很完美,ECB、CBC模式均支持,呵呵,幸福了 。 参考C#示例代码一通修改测试,省略几昼夜苦干的吐槽终于开花结果: 呵呵,这个或者是网上目前唯一的开源的Delphi版的微信加解密算法单元吧,激动! {*******************************************************************

Convert Encrypt code in java to Ruby

佐手、 提交于 2019-11-30 07:41:37
I have been trying to convert a code for encrypt in java to ruby, but I am not able to do it completely. I getting different values. passphrase = passphrase + STATIC_KEY; byte[] key = passphrase.getBytes("UTF-8"); MessageDigest sha = MessageDigest.getInstance("SHA-1"); key = sha.digest(key); key = Arrays.copyOf(key, 16); SecretKey secretKey = new SecretKeySpec(key, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); IvParameterSpec initialisationVector = new IvParameterSpec( new byte[16]); cipher.init(Cipher.ENCRYPT_MODE, secretKey, initialisationVector); byte[] encryptedData =

c# AES Decryption

核能气质少年 提交于 2019-11-30 07:36:34
I am working with SagePay Forms and currently converting the VB examples they have to c#. I have made good progress so the encryption part of my project works fine (SagePay can decrypt it). The issue I am having is that when I attempt to decrypt the string, it turns to garbage. If anyone has done this before I would really appreciate some help with my decryption code. I have included the encryption code which works and the first two lines are the setup and call from another method. I haven't added the VB code but if this is required I could add it. Didn't want a huge post if not required.

Reading from a cryptostream to the end of the stream

孤人 提交于 2019-11-30 07:36:06
问题 I'm having some trouble with the code below. I have a file in a temporary location which is in need of encryption, this function encrypts that data which is then stored at the "pathToSave" location. On inspection is does not seem to be handling the whole file properly - There are bits missing from my output and I suspect it has something to do with the while loop not running through the whole stream. As an aside, if I try and call CryptStrm.Close() after the while loop I receive an exception.

iOS encryption AES128/CBC/nopadding why is not working?

邮差的信 提交于 2019-11-30 07:35:42
I have an app that needs to encode some data using AES/CBC/no padding. The app is ported also on android. There the encoding is done like this: byte[] encodedKey = getKey(); SecretKeySpec skeySpec = new SecretKeySpec(encodedKey, "AES"); AlgorithmParameterSpec paramSpec = new IvParameterSpec(initializationVector); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, paramSpec); int blockSize = cipher.getBlockSize(); int diffSize = decrypted.length % blockSize; System.out.println("Cipher size: " + blockSize); System.out.println("Current size: " +

Client-side encryption over HTTP with Diffie-Hellman Key Exchange and AES

岁酱吖の 提交于 2019-11-30 07:18:50
After watching a YouTube video on the Diffie-Hellman Key Exchange , I wanted to try an implementation in JavaScript (Atwood's law). I sketched up an cipher on Node.js with the following rules: Step 1: Client and server agree on a shared key: Client & server start with a 512bit prime public key pK Client generates a 512bit prime private key kC and sends powMod(3, kC, pK) Server generates a 512bit prime private key kS and sends powMod(3, kS, pK) Client & Server use powMod(response, privatekey, pK) as the shared key Step 2: Communication Before a client sends data it is encrypted with the shared

AES Encryption Java Invalid Key length

余生长醉 提交于 2019-11-30 07:11:53
I am trying to create an AES encryption method, but for some reason I keep getting java.security.InvalidKeyException: Key length not 128/192/256 bits Here is the code: public static SecretKey getSecretKey(char[] password, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException{ SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); // NOTE: last argument is the key length, and it is 256 KeySpec spec = new PBEKeySpec(password, salt, 1024, 256); SecretKey tmp = factory.generateSecret(spec); SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES"); return

Alternatives for DatatypeConverter in Android

旧城冷巷雨未停 提交于 2019-11-30 07:08:33
I trying implement algorithm AES 128 in Android but it doesn't work, the problem is import javax.xml.bind.DatatypeConverter; DatatypeConverter.parseHexBinary(key) and DatatypeConverter.printBase64Binary(finalData) Does an alternative exist? My method: private static final String ALGORIT = "AES"; public static String encryptHackro(String plaintext, String key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, IOException, DecoderException { byte[] raw = DatatypeConverter.parseHexBinary(key); SecretKeySpec skeySpec = new

How to encrypt a file in java using AES [duplicate]

依然范特西╮ 提交于 2019-11-30 06:56:44
This question already has an answer here: Java 256-bit AES Password-Based Encryption 9 answers I need to know how to create an AES and using it to encrypt and decrypt a file in java. Try using a CipherOutputStream and passing in a FileOutputStream . See http://www.java2s.com/Tutorial/Java/0490__Security/UsingCipherOutputStream.htm for a quick example, just use Cipher.getInstance("AES/CBC/PKCS5Padding") instead. 来源: https://stackoverflow.com/questions/5307499/how-to-encrypt-a-file-in-java-using-aes

Android encryption “pad block corrupted” exception

纵饮孤独 提交于 2019-11-30 06:48:46
问题 In this code, this line is causing an exception: clearText = c.doFinal(Base64.decode(encryptedText, Base64.DEFAULT)); javax.crypto.BadPaddingException: pad block corrupted I got the code from: http://www.techrepublic.com/blog/software-engineer/attention-android-developers-keep-user-data-safe/ Any ideas? private String decrypt (String encryptedText) { byte[] clearText = null; try { SecretKeySpec ks = new SecretKeySpec(getKey(), "AES"); Cipher c = Cipher.getInstance("AES"); c.init(Cipher