w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
RSA Encryption/Decryption Convert Byte[] to String and Vice Versa
You shouldn't convert binary data to a String. You can, for example, encode it with Base64 encoding if you want it as a printable String. Try the following: import android.util.Base64 ... byte[] cipherData = cipher.doFinal(encryptedBytes); String cipherString = Base64.encodeBytes(cipherData);

Categories : Android

DES encryption/decryption
First of all: never use eof() to check whether the end of file is reached since it doesn't predict the end of file. while(h.read(plaintext,64)) { if (std::h.gcount() < 64) // gcount returns the number of characters extracted by the last unformatted input operation. for (int i=std::h.gcount(); i<64; i++) paintext[i] = 0; // pad the last block chyphertext=d1.Encrypt(plaintext); //decryption is the same.just change Encrypt to Decrypt k.write(chyphertext,64); }

Categories : C++

Encryption/ Decryption
Your GenerateKey Method generates a new (random) key every time you call it (like you already stated in the comments there). If you want to use a random key, store the generated key somewhere and use it for decryption and encryption. You can use a own "password" for encryption by giving your encryption/decryption method a own string value. e.g. crypto.EncryptFile(@"D:Testingrownfox.txt", @"D:Testingrownfox_enc.txt", "abcd1234"); crypto.DecryptFile(@"D:Testingrownfox_enc.txt", @"D:Testingrownfox_dec.txt", "abcd1234"); As you can see in the MSDN reference to "DES.Key", DES supports keys with a length of 64bit, so it's important to note, that the string must have 8 characters.

Categories : C#

Java AES-128 Encryption Decryption
The compiler tells you what the problem is. no suitable method found for decode(String,int) You can't do this byte[] cipheredBytes = Base64.decode(plainTextString, Base64.BASE64DEFAULTLENGTH); because it doesn't match any method signatures on Base64 You shouldn't use classes that start with com.sun.* or sun.* as they are internal parts of the Oracle JRE and not guaranteed to have a stable API or even be present in all JREs. Instead, if you want a built-in class, you can use javax.xml.bind.DatatypeConverter and call the static method DataTypeConverter.parseBase64Binary(String), passing your Base64 encoded String as the argument. The return value will be a byte[] which is what you need.

Categories : Java

Encryption - Decryption, Database
Try this function encryption($x) { $key = 'SuperSecretKey'; $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $x, MCRYPT_MODE_CBC, md5(md5($key)))); return $encrypted; } function decryption($y) { $key = 'SuperSecretKey'; $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($y), MCRYPT_MODE_CBC, md5(md5($key))), ""); return $decrypted; }

Categories : PHP

Encryption & Decryption algorithm
public string PassEncrypt(string Password) { // Encrypting the password entered by User // ====================================================== MD5 md5 = new MD5CryptoServiceProvider(); md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(Password)); byte[] result = md5.Hash; StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < result.Length; i++) { strBuilder.Append(result[i].ToString("x2")); } return strBuilder.ToString(); // ====================================================== } OR You may refer on this links : developer.motorala.com codereview.stackexchange.com android snippets java-tips.org

Categories : Android

AES Encryption in IOS to Decryption in JAVA
Short Answer Your Java code is using PBKDF2 to transform your key, and it looks like your Obj-C code is not (though you haven't given enough code for us to be sure). So the key is different, which is why your decryption is not working. Unsolicited Free Advice It looks like you're just cutting and pasting code from different places without really understanding it. If you want to use crypto, you need to understand what you're doing or you can really mess things up (even if they seem to be working). If you don't know the difference between a password and a key, or what PBKDF2 is and when to use it, then you need to do some basic research.

Categories : Java

AES (aes-cbc-128, aes-cbc-192, aes-cbc-256) encryption/decryption with openssl C
Take a peek at this modified version of your code. Note the following: Added hex_print (minor) Added proper sizing of key buffer (medium). Added proper sizing of output encryption buffer (which must be a block-size multiple, and if original source buffer is an exact block-size multiple, you still need one full block of padding (see PKCS 5 padding for more info). Same IV used for both encrypt and decrypt. Finally, odd as it may seem AES_cbc_encrypt() is used for both encryption and decryption (see the last parameter in the call). Source Code #include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/aes.h> #include <openssl/rand.h> // a simple hex-print routine. could be modified to print 16 bytes-per-line static void hex_print(const voi

Categories : C

AES (aes-ige-128, aes-ige-192, aes-ige-256) encryption/decryption with openssl C
The error message says it all. aes_ige.c(88): OpenSSL internal error, assertion failed: (length%AES_BLOCK_SIZE) == 0 This is basically a run-time-check (assertion) that fails due to invalid input provided to the function AES_ige_encrypt() present in the source at line 88 of aes_ige.c. OPENSSL_assert((length%AES_BLOCK_SIZE) == 0); The assertion basically checks if length (the 3rd parameter passed to the function) is an integral multiple of AES_BLOCK_SIZE. If yes, the execution continues, otherwise the program halts and prints warning about the assertion having failed. So ensure that the size of the data being passed to AES_ige_encrypt() is a multiple of AES_BLOCK_SIZE. If size of the data is not an integral multiple, then append NUL bytes to it to make the total size the nearest mul

Categories : C

c++ encryption, c# decryption = failure
At first glance, it appears that you are using 8-bit char strings ("string") instead of unicode strings (L"blah" or wchar_t*) in your C++ code. C# uses Unicode for strings. That may be why you are getting different results. My first check would be to make sure that I'm passing the C++ strings as unicode. Good luck, hope this helps. :)

Categories : C#

C# RSA encryption/decryption with transmission
well there are really enough examples for this, but anyway, here you go using System; using System.Security.Cryptography; namespace RsaCryptoExample { static class Program { static void Main() { //lets take a new CSP with a new 2048 bit rsa key pair var csp = new RSACryptoServiceProvider(2048); //how to get the private key var privKey = csp.ExportParameters(true); //and the public key ... var pubKey = csp.ExportParameters(false); //converting the public key into a string representation string pubKeyString; { //we need some buffer var sw = new System.IO.StringWriter(); //we need a serializer var xs = new System.Xml.Serialization.XmlSerializer(typeof(RSAParameters)); //serialize th

Categories : C#

aes 256 encryption on PHP and decryption with ios pannding
The difference is is the padding. The PHP solution does not perform a standardized padding mechanism. Instead it uses zero-padding, which can lead to trouble if the plain text ends with a string of 00h valued bytes as they will be removed from the plain text by the unpadding mechanism (or any trim or right_trim method for that matter). You should pad the plain text before encryption in PHP, just like CCCrypt does. CCCrypt uses a good standardized padding mode called PKCS#7 padding. This mode always pad 1 to 16 (blocksize) bytes. The value of the bytes are identical to the number of padding bytes. In your example it is 0Ch in hexadecimals, or 12 padding bytes. Check out this link to StackOverflow on how to pad/unpad in PHP. Padding/unpadding is always performed on the raw plain text, neve

Categories : PHP

Encryption/Decryption in C# and Java
I think this question is similar to: NoSuchMethodError using commonc codec in Android application and Apache Commons Codec with Android: could not find method Answer is, Android uses version 1.2 of the apache commons.

Categories : C#

Blowfish encryption and decryption in C
I think you're supposed to switch the from and to variables: //as WhozCraig mentioned, fill in n and iv again before decryption n = 0; /* internal blowfish variables */ /* fill the IV with zeros (or any other fixed data) */ memset(iv, 0, 8); BF_cfb64_encrypt(to, from, len, &key, iv, &n, BF_DECRYPT); printf("File %s has been decrypted to --> %s ",to, from); //FAILS DOES NOT DECRYPT Retaining the original IV (which isn't hard; it was all zeros) and resetting n to zero before the decryption will get what the OP wants - WhozCraig

Categories : C

RSA Encryption and Decryption on Different Machines
It seems that you don't fully understand of how public key encryption works. Both partners have to generate their own public/private key pair. Afterwards, you share the public keys (that is, M1 sends its public key to M2 and vice versa). In reality, there is the problem of key distribution and authentication, i.e. how do I know that a public key that says it belongs to John really belongs to John? But for your small example, you can ignore this at first. Once both machines have the partner's public keys, you encrypt a message going from M1 to M2 using M2's public key. M2 then decrypts it using its private key. Apply the same idea for the reverse direction. That way, you never have to share any of the prime factors or the private keys (as you correctly noticed, doing that would completel

Categories : C++

Encryption and Decryption in Different Program
You can either Write two programs, each with their own main. Use the argvyou send into main to tell it what you want it to do. For option 2, there is another question here. In essence, after checking the arg count, argc, and remembering argv[0] is your program, you could say if(strcmp(argv[1], "ENCRYPTION")==0) { //... do ENCRYPTION }...

Categories : C++

node.js rsa encryption/decryption
I'm pretty sure this Node module will be able to do what you want. This Node module provides a fairly complete set of wrappers for the RSA public/private key crypto functionality of OpenSSL. Take a look at this answer for a possible way of converting the XML key into a standard PEM key that can be used by the Node module.

Categories : Javascript

Java data encryption/decryption
When it comes to store secure data you have to ask yourself some basic questions : Do I have to keep the original data, or do only have to test its identity (=> use of hash algorithms) If I use encryption, how will I store my keys ? Will I need public key (asymmetric) cryptography (=> use of pki and certificates) These are the main concerns to have. Then, technically, the best way to implement it is a matter of what library you will have to choose. Take a look at http://www.bouncycastle.org/.

Categories : Java

Rijndael AES-128 encryption decryption in Ruby
require 'openssl' cleartext = '2~1~000024~0910~20130723092446~T~00002000~USD~F~375019001012120~0~0~00000000000~' key = 'abcdef0123456789abcdef0123456789' iv = '0000000000000000' cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc") cipher.encrypt cipher.padding = 0 cipher.key = [key].pack('H*') cipher.iv = [iv].pack('H*') encrypted = cipher.update(cleartext) encrypted << cipher.final puts encrypted.unpack('H*').first.upcase Output: 0D5835AFEBEE04C6DC2421538DB7C38A1283970EB31F21A47D2E3CC623D29EF0461279C7ACF93B031BE2B69CE45C9339554957F29EF609F019EEC975983A03B537622D7E0F196BE148F1C7CBB88E602A

Categories : PHP

Inconsistent Encryption / Decryption Results
Have you checked the two columns in the Settings table? Do they have the same data types? And are you sure the encrypt() and decrypt() methods work correctly? After you get this working, you should consider using a random generated salt for each password and store the salt in the table together with the password.

Categories : PHP

Android RSA encryption and Python decryption
The Java code is using PKCS#1 v1.5 RSA encryption, which is a seriously broken and unsecure protocol. Having said that, the decryption is done in Python with the appropriate module: from Crypto.Cipher import PKCS1_v1_5 priv_key = RSA.importKey(f) cipher = PKCS1_v1_5.new(priv_key) plain_text = cipher.decrypt(encrypted_text) More more information, see the module documentation.

Categories : Java

AES256 Encryption/Decryption in both NodeJS and C# (.Net)
Okay, upon inspecting the node.js source for crypto, I determined, that the encoding was using a new Buffer(passkey, 'binary'), which was only using the original value xand 0xFF for the bytes used, so I created a matching method in C#... here's the method in question... private static byte[] RawBytesFromString(string input) { var ret = new List<Byte>(); foreach (char x in input) { var c = (byte)((ulong)x & 0xFF); ret.Add(c); } return ret.ToArray(); } And the updated/working CryptoUtil.cs using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace T1.CoreUtils.Utilities { public static class CryptoUtility { /* Wanting to stay

Categories : C#

Interop Encryption/Decryption between Java/Net with AES and specifying IV and Key
Next time you can actually use Java to C# converter online application such as https://www.varycode.com/converter.html Which will actually reduce typing problems by copy paste!

Categories : C#

RNCryptor IOS + Javascript encryption / decryption AES 256
Please follow the documentation for the RNCryptor file format: https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor-Spec-v3.md You should be able to derive all the necessary data from file and add your shared secret... Specification for RNCryptor data format version 3 Byte: | 0 | 1 | 2-9 | 10-17 | 18-33 | <- ... -> | n-32 - n | Contents: | version | options | encryptionSalt | HMACSalt | IV | ... ciphertext ... | HMAC | version (1 byte): Data format version. Currently 3. options (1 byte): bit 0 - uses password encryptionSalt (8 bytes): iff option includes "uses password" HMACSalt (8 bytes): iff options includes "uses password" IV (16 bytes) ciphertext (variable) -- Encrypted in CBC mode HMAC (32 bytes) All data is

Categories : Javascript

Encryption and decryption with AES PKCS7Padding Fails
You have several mistakes: Don't convert ciphertext to a string - this is likely to be a lossy conversion. Instead, keep it as a byte array or convert it to hexadecimal or base64. You need to store the IV for use during decryption. Currently you just throw it away (in your enc method). A common technique is to prefix the ciphertext with your IV (possibly separated by a delimiter). When you create a string from your decrypted bytes, you should specify a charset. This might not be an exhaustive list, but it's certainly enough to cause you major problems. Fix these and then let us know if you are still seeing errors (and post the errors in your question). Also, returning a string with "error" is poor design. In Java, use exceptions to indicate something has gone wrong.

Categories : Java

iOS symmetric key encryption / decryption equivalent to Java
You have at least two problems: The Objective C code is using ECB mode, while the Java code is using CBC mode. Use a bytearray of zeroes instead of NULL in the CCrypt-invocation to use CBC mode with a zero IV like the Java code. Since keyBytes is 24 bytes long, Java will use AES-192. CCrypt will just ignore the extra bytes. Either specify AES-192 to CCrypt or use a 128 bit key ("keykeykeykeykeyk" should work).

Categories : Java

Assembly code. Encryption to Decryption Routine
The algorithm is symmetric because i could decrypt back every character and key combination. These two functions were tested by a loop for any error in decrypting the value back: #include <iostream> using namespace std; unsigned char enc(unsigned char ch, unsigned char key) { unsigned char tmp = key^(~ch+(unsigned char)0x04); return (( (tmp<<3) | (tmp>>5) ) & 0xff)-0x02; } unsigned char dec(unsigned char ch, unsigned char key) { unsigned char tmp = (ch+0x02); tmp = ((tmp>>3) | (tmp<<5)) & 0xff; return ~((tmp^key )-(unsigned char)0x04); } int main() { // single encryption test char c = 'A'; char key = 'K'; cout << "single test:" << (char)enc(c, key) << endl; bool problem = false; int k,

Categories : Assembly

How to speed up java card encryption/decryption(RSA)
RSA is inherently slow, and gets slower when you use bigger key lengths. There are however things you can do to speed up RSA operations: Use a public key with a public exponent that has few bits set to 1, e.g. the fourth number of Fermat, 65537. Note that there are some attacks that can be performed on a public exponent with value 3. This only speeds up public key operations. use a RSAPrivateCrtKey that includes parameters that can be used for calculations using the Chinese Remainder Theorem. This only speeds up private key operations. If you have already generated a key pair on the card, chances are that both options have already been lifted by the chip. In that case the solution space may be empty. The only thing you can do then is to switch to Elliptic Curve cryptography (but even t

Categories : Performance

CryptoJS AES encryption and JAVA AES decryption value mismatch
Your Java code is riddled with errors. Here are a few of them: Your initial exception is caused because your "Secret Passphrase" string contains 17 bytes. You need to truncate this to 16 bytes (or pad it to match 24 or 32 bytes). You need to match the behaviour of the CryptoJS library. You are trying to hex-decode data that appears to be base64 encoded. Try using DatatypeConverter.parseBase64Binary(hex);. You are creating a secret key with the algorithm "AES/CTR/NoPadding". This in invalid, just use "AES". You must pass an IV/nonce value into your decryption: cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(...)); The value you use will depend upon what CryptoJS is doing. Perhaps it uses all zeroes? Perhaps it generates a random one and you need to store it with the cipherte

Categories : Java

Data differs after encryption and consecutive decryption with AES
assertEquals(data.hashCode(), received.hashCode()) is very unlikely to pass unless data and received refer to the same object (since byte arrays inherit the identity hash code method from Object). I don't see where data comes from, but that is probably not the case here. You should use Arrays.equals(data, received). Apart from that, there are various cryptographic issues here: Random is not "random enough" for cryptographic purposes; you should use SecureRandom. Key derivation using plain SHA-256 is dubious. You should consider using a key derivation algorithm that is specifically designed for this, like PBKDF2. AES with 256-bit keys is not always better than 128-bit keys. Check this page. In this case it's completely bogus since passphrases rarely even reach 128 bits of entropy. Random

Categories : Java

Java AES encryption/decryption always return the same content
This is the problem: public SecretKeySpec generateSecretKey(String password) throws Exception { MessageDigest shahash = MessageDigest.getInstance("SHA-1"); byte[] key = shahash.digest(); key = Arrays.copyOf(key, 16); return new SecretKeySpec(key, "AES"); } You don't use password anywhere within generateSecretKey, so it'll create the same secret key every time... If you change it to: public SecretKeySpec generateSecretKey(String password) throws Exception { MessageDigest shahash = MessageDigest.getInstance("SHA-1"); byte[] key = shahash.digest(password.getBytes("UTF-8")); key = Arrays.copyOf(key, 16); return new SecretKeySpec(key, "AES"); } then it will fail as expected when given the wrong password. That doesn't necessarily mean it's the best way of

Categories : Java

Encryption - Decryption with AES/BlowFish/DESede and Enum
The theme of the problem is misunderstanding of the relationship between Strings and bytes. At the end of the encrypt method, what do you think these two lines do: byte[] ciphertext = cipher.doFinal(... return new String(ciphertext); The last line takes the encrypted bytes, which could be almost anything, and attempts to interpret those bytes as encoding some characters of a string. Using what encoding? String constructor with no character encoding argument uses system default encoding, which depends on JVM/OS/Locale. Lets say it is UTF-8. Are you guaranteed that there will actually be some character for the encrypted bytes? Answer: NO. Will you get the same bytes back, when you take the resulting string and call .getBytes("UTF-8"). Answer: No, there are mutliple byte sequences en

Categories : Java

Delphi DEC Twofish Encryption and server-side decryption in PHP
KDFx is an proprietary incompatible key derivation method, from the source: "class function TDECHash.KDFx // DEC's own KDF, even stronger". You will have problens using this from DEC and PHP and should use other libraries. The problem is discussed e.g. in http://www.delphipraxis.net/171047-dec-5-2-mit-vector-deccipher-umbau-von-dot-net-auf-delphi.html

Categories : PHP

XML encryption and decryption for multiple recipients with X509 certificates
The EncryptedElement class can take as many EncryptedKeys as you want. As long as the other party can correctly identify their EncryptedKey (using the Recipient or the KeyInfoName elements), you should not have any problems: // example xml XmlDocument xdoc = new XmlDocument(); xdoc.PreserveWhitespace = true; xdoc.LoadXml(@"<root><encryptme>hello world</encryptme></root>"); var elementToEncrypt = (XmlElement)xdoc.GetElementsByTagName("encryptme")[0]; // keys // rsa keys would normally be pulled from a store RSA rsaKey1 = new RSACryptoServiceProvider(); RSA rsaKey2 = new RSACryptoServiceProvider(); var publicKeys = new[] { rsaKey1, rsaKey2 }; string sessKeyName = "helloworldkey"; var sessKey = new RijndaelManaged() { KeySize = 256 }; // encrypt var encXml = new

Categories : C#

AES 128 encryption/decryption using Random salt and Initialization vector
Base64 is used to make raw bytes into text, so they can be passed to programs/methods that work with text. It is nothing specifically to do with encryption. A good crypto function will produce raw bytes and Base64 is just a way of representing them as printable text. Random salt is used for creating secure cryptographic keys. See RCF 5869 for the use of salt in HKDF (HMAC based Key Derivation Function). An Initialization Vector (IV) is used for AES in CBC mode. The IV does not need to be kept secret and can be prepended to the actual cyphertext when you send it. There will usually be a parameter for the IV in whatever crypto library you are using. If you require authentication as well as security, then you should look at using an HMAC as well.

Categories : Iphone

AES - Encryption with Crypto (node-js) / decryption with Pycrypto (python)
So we started from the "How can i decrypt... OpenSSL" 's answer. We needed to modify the encryption script which gave: crypto = require "crypto" [...] var iv = new Buffer('asdfasdfasdfasdf') var key = new Buffer('asdfasdfasdfasdfasdfasdfasdfasdf') var cipher = crypto.createCipheriv('aes-256-cbc', key, iv); cipher.update(new Buffer("mystring")); var enc = cipher.final('base64'); [...] iv needs to be 16bytes long, key is 32bytes. And we changed createCipher to createCipheriv. Back to the python decryption script: Process was simply reading PyCrypto's documentation, and compare with the code we started from. Then we decided to just stick to the API, and start from scratch. And it gave: from base64 import b64decode from Crypto.Cipher import AES [...] iv = 'asdfasdfasdfasdf' key = 'asdf

Categories : Python

Encryption using passlib.hash - sha256_crypt.encrypt and decryption
Is it possible to retrieve the original password? No. The purpose of a password hashing function is to make it possible for you to authenticate users without actually storing their passwords. Hashing functions are one-way, so given the output, you cannot infer what the input was. Think of it like adding two numbers together. You know that 2 + 2 = 4, but given 4, you can't figure out that the two numbers that were added together were 2 and 2. If not what is the best alternative? You most likely don't need encryption. You need a good password hashing function, like Bcrypt or PBKDF2.

Categories : Python

A fast encryption/decryption algorithm that will NOT be used for security, but to combat spam
Look at this article on block ciphers. Here is how you can make your own cipher: Encryption: Store your own private data, preferably randomly generated for each cipher. Using your private data as a seed in a pseudorandom number generator. Produce a string of bits as long as the data you want to encode, a.k.a. the plaintext. This string of "random" bits is the key. For each bit of the key, take the corresponding bit from the plaintext, which we will call a and b respectively. The XOR of the two yields the corresponding bit in the ciphertext. Use the ciphertext as you wish. Decryption: Take the ciphertext and retrieve the private data for it. Use the private data as a seed in the same pseudorandom number generator to produce the key from before. Follow the steps above to get the plain

Categories : Performance

Android RSA decryption (fails) / server-side encryption (openssl_public_encrypt)
OpenSSL uses padding = OPENSSL_PKCS1_PADDING by default. So to have the same padding mechanism at both sides you should use Cipher.getInstance("RSA/ECB/PKCS1Padding"). This is also what you could use in Java SE. Note that it is very dangerous to depend on default modes of operation in cryptography. Many implementations have different defaults, and those can be hard to look up. So always try to fully specify the algorithm/mode to use. You could try other RSA padding modes, but note that - unfortunately - Android has disabled a lot of algorithms and aliases from the Bouncy Castle source code they adapted.

Categories : Android

Oracle Fusion Middleware Encryption / Decryption Sensitive Payload Data
What you can do is create an Encryption/Decryption Web Service and use it in BPEL, OSB and you ADF application if you want, there are many Encryption Algorithms with this solution you should be able to choose what you want to use.

Categories : Oracle



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.