aes

GO与PHP的AES交互,key长度问题

淺唱寂寞╮ 提交于 2019-12-11 02:32:36
今天在使用go与php的AES加解密交互中,一直有个问题那就是在go中加密后,在php端始终都是无法解密,经过排查最后发现是加密key长度引起的问题, 这里简单记录下。 go的AES使用的是第三方的库, openssl ,因为用的匆忙,没注意看文档,所以就直接弄了示例代码,才发现和php端无法解密,其实在文档中它其实讲的很清楚了, “The length of the key can be 16/24/32 characters (128/192/256 bits)”,这个key的长度只能是16,24和32个字符,分别对应AES-128, AES-192, or AES-256等模式。 我在php中因为没有太在意这个长度,所以搞的32位,但由于我用的是ECB模式,所以其实32位的字符长度实际是截成16个字符了,那么我在go中还配置成32个字符就不对了,直接在go中把key的长度改成php中配置的key的一半就行了,哎,你说这坑货php,如果key配置不对提示下多好。 go代码 func Encrypt(data map[string]interface{}) (s string) { src,_ :=json.Marshal(data) key := []byte("YzfNCQoF9P7tjwyZ") dst , err := openssl.AesECBEncrypt(src,

openssl equivalent for AES256EncryptWithKey method

妖精的绣舞 提交于 2019-12-11 02:21:18
问题 How to get the same result as the following objective-c encrypting method with the command line openssl ? - (NSData *)AES256EncryptWithKey:(NSString *)key { NSData *returnData = nil; char keyPtr[kCCKeySizeAES256+1]; bzero(keyPtr, sizeof(keyPtr)); [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; NSUInteger dataLength = [self length]; size_t bufferSize = dataLength + kCCBlockSizeAES128; void *buffer = malloc(bufferSize); size_t numBytesEncrypted = 0;

Generating signed and encrypted JWT

半腔热情 提交于 2019-12-11 02:11:19
问题 I'm trying to generate a signed and encrypted JWT token using Nimbus JWT. private void generateToken() throws JOSEException, NoSuchAlgorithmException, UnsupportedEncodingException { KeyGenerator keyGen = KeyGenerator.getInstance("AES"); keyGen.init(256); SecretKey secretKey = keyGen.generateKey(); JWSSigner signer = new MACSigner(secretKey); JWTClaimsSet claimsSet = new JWTClaimsSet.Builder().subject("subject").build(); SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256),

nodeJS: can't get crypto module to give me the right AES cipher outcome

痴心易碎 提交于 2019-12-11 01:21:28
问题 I'm trying to use the nodeJS crypto module to encrypt some hex strings using the ECB mode of AES 128. To do so, I'm using the following code: cryptoAES = function (sInput, sKey, bEncrypt) { return crypto('AES-128-ECB', sInput, sKey, bEncrypt); }; crypto = function (sAlgo, sInput, sKey, bEncrypt) { var result = ""; if (bEncrypt){ var cipher; var bKey = new Buffer(sKey, 'hex'); var bInput = new Buffer(sInput, 'hex'); cipher = crypto.createCipher(sAlgo, bKey); cipher.setAutoPadding(false);

Incorrect key size when porting Crypto++ AES encryption to PHP's mcrypt

血红的双手。 提交于 2019-12-11 01:14:15
问题 Earlier I managed to port some C++ CryptoPP Rijndael_128 CBC code to MCrypt PHP, but now I'm having problems with CFB mode. The C++ and PHP results do not match (well the first byte matches but this could be coincidence, everything else doesn't). With some diagnostics, it looks like PHP's mcrypt is not setting the key length correctly? Here's the C++ (diagnostics and sundries removed for simplicity): CFB_Mode<AES>::Encryption encryptor(g_encrypt_key, AES::DEFAULT_KEYLENGTH, g_encrypt_iv);

AES Encrypt in CryptoJS and decrypt in Coldfusion

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 01:07:11
问题 We've got a Silent Login service written in Coldfusion9 that accepts encrypted strings from external systems and then decrypts based on an agreed Algorithm/Encoding setup. This has worked without issue for years now from systems running ASP/JAVA/PHP, but we now have a client who has no choice but to use CryptoJS to perform the encryption and for the life of me I cannot work out why this won't decrypt in Coldfusion. My knowledge of encryption isn't brilliant but the thing I am noticing is the

Whats wrong with this simple NodeJS crypto function?

限于喜欢 提交于 2019-12-11 00:45:19
问题 I'm trying to perform AES CBC encryption with zero padding of a url query string. I'm using NodeJS's core crypto module. It's for use with http://www.blackoutrugby.com/game/help.documentation.php#category=35 I have a key and IV. When testing the following function I'm not getting the string returned in full. I believe this has to do with padding but am unsure how to apply it correct. If it is the padding, can anyone show me how I should apply it? If not where am I going wrong? Also is cipher

PHP Decrypting AES returns padding at front of string?

好久不见. 提交于 2019-12-11 00:15:02
问题 I've been wrestling with decrypting a given string, generated by a remote ColdFusion server, in PHP using AES in CBC mode with PKCS5 padding. I've gotten to the point where I can decrypt the string almost perfectly, the issue is there appears to be some cruft at the beginning of the string. I thought padding happened at the end, but looking at the decrypted string, there's nothing at the end, but the beginning is padded out so the string is 64 characters long (the original string is 32

unable to use aes files of openssl in qt creator [duplicate]

流过昼夜 提交于 2019-12-10 23:33:30
问题 This question already has answers here : How to Include OpenSSL in a Qt project (5 answers) Closed 5 years ago . I am trying to include AES header file an #include <openssl/aes.h> in Qt4 Creator but while compiling its giving error as openssl/aes.h: No such file or directory . Please tell me how to include to this file so that I can use AES functions in my program? 回答1: If this is on Linux, add the following into your .pro file: PKGCONFIG += openssl It will handle all necessary header paths,

AES Encryption- large files

↘锁芯ラ 提交于 2019-12-10 21:57:35
问题 I am doing AES encryption using EVP interface of OpenSSL in C language in the 128/192/256 cbc modes. I found a nice example in stackoverflow with which I have started programming. What I would like to know is: What is the default padding used while encryption? What happens if I have large data. Do I have to code to divide it into data blocks of 128 bits? or does EVP interface takes care of it? What should be the size of the IV for 128bit, 192bit and 256bit cbc modes(where only the key lengths