Org.BouncyCastle.Crypto.Modes.GcmBlockCipher.GetOutputSize C# (CSharp) Method

GetOutputSize() public method

public GetOutputSize ( int len ) : int
len int
return int
		public virtual int GetOutputSize(
			int len)
		{
			if (forEncryption)
			{
				return len + bufOff + macSize;
			}

			return len + bufOff - macSize;
		}

Usage Example

Example #1
0
        public static IDStorage decryptKeyStoreStorage(byte[] c_baKey, byte[] c_baIV, string c_sBase64JsonStorage)
        {
            const int MacBitSize = 128;
            byte [] baPayload = new byte[0];

            var decryptCipher = new GcmBlockCipher(new AesFastEngine());
            var parameters = new AeadParameters(new KeyParameter(c_baKey), MacBitSize, c_baIV, baPayload);
            decryptCipher.Init (false, parameters);

            byte[] baEncryptedStorage = Convert.FromBase64String (c_sBase64JsonStorage);

            var decryptedText = new byte[decryptCipher.GetOutputSize(baEncryptedStorage.Length)];
            try
            {
                var len = decryptCipher.ProcessBytes(baEncryptedStorage, 0, baEncryptedStorage.Length, decryptedText, 0);
                decryptCipher.DoFinal(decryptedText, len);
            }
            catch (InvalidCipherTextException)
            {
                //Return null if it doesn't authenticate
                return null;
            }

            string sJsonStorage = Encoding.GetEncoding (1252).GetString (decryptedText);
            IDStorage _KeyStoreStorage = JsonConvert.DeserializeObject <IDStorage> (sJsonStorage);

            return _KeyStoreStorage;
        }
All Usage Examples Of Org.BouncyCastle.Crypto.Modes.GcmBlockCipher::GetOutputSize