vb.net - How to use PKCS7 with BouncyCastle Rijndael in .Net -
i'm working on project requires me cipher data using rijndael, cbc , pkcs7...
i have examples show me initial data , result should after applying rijndael... tried using .net rijndaelmanaged class got nothing similar expected value , believe it's because of issue while converting byte array string...
on other hand, using bouncycastle's rijndael implementation managed similar expected value, , difference can't set pkcs7 padding mode... , biggest issue cannot find documentation anywhere!
here's simplified version of encrypt function, notice included key , iv definitions here testing.
public shared function encrypt(data byte()) byte() dim thecipher new org.bouncycastle.crypto.engines.rijndaelengine() dim ciphr new paddedbufferedblockcipher(new cbcblockcipher(thecipher), new pkcs7padding()) dim key new keyparameter(system.text.encoding.utf8.getbytes("---examplekey---")) dim iv byte() = system.text.encoding.utf8.getbytes("---example-iv---") dim ivkey new parameterswithiv(key, iv) ciphr.init(true, ivkey) dim size integer = ciphr.getoutputsize(data.length) dim result(size) byte dim olen integer = ciphr.processbytes(data, 0, data.length, result, 0) olen += ciphr.dofinal(result, olen) if olen < size dim tmp(olen) byte array.copy(result, 0, tmp, 0, olen) result = tmp end if return result end function
basically plain text n times blocksize. means full block of padding added before encryption, resulting in additional block of ciphertext. furthermore, because way vb creates arrays, need use dim varname(size - 1) byte
.
Comments
Post a Comment