如何在C#中转换java代码

如何在C#中转换java代码

本文介绍了如何在C#中转换java代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static final String AES_TRANSFORMATION = "AES/ECB/PKCS5Padding";
	public static final String AES_ALGORITHM = "AES";
	public static final int ENC_BITS = 256;
	public static final String CHARACTER_ENCODING = "UTF-8";

	private static Cipher ENCRYPT_CIPHER;
	private static Cipher DECRYPT_CIPHER;
	private static KeyGenerator KEYGEN;

	static{
		try{
			ENCRYPT_CIPHER = Cipher.getInstance(AES_TRANSFORMATION);
			DECRYPT_CIPHER = Cipher.getInstance(AES_TRANSFORMATION);
			KEYGEN = KeyGenerator.getInstance(AES_ALGORITHM);
			KEYGEN.init(ENC_BITS);
		}catch(NoSuchAlgorithmException | NoSuchPaddingException e) {
			e.printStackTrace();
		}
	}
	private static String generateSecureKey() throws Exception{
		SecretKey secretKey = KEYGEN.generateKey();
		return encodeBase64String(secretKey.getEncoded());
	}





我的尝试:

i得到不同的输出#



从以下评论中添加 - Nelek

i试图生成密钥



What I have tried:

i have getting different output when conver to c#

addition from comment below - Nelek
i have tried to genrate key

public byte[] GenerateKey()
    {

        using (var aes = CreateAes256Algorithm())
        {

            aes.GenerateKey();
            return aes.Key;
        }
    }

    private RijndaelManaged CreateAes256Algorithm()
    {
        return new RijndaelManaged { KeySize = 256, BlockSize = 128, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 };
    }

推荐答案


这篇关于如何在C#中转换java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 10:08