Rijndael을 사용하여 암호화 된 mp4가 있고 다음과 같은 방법으로 C#에서 해독합니다.C# 용 Java의 암호화/암호 해독 도구
System.Security.Cryptography.Rijndael crypt = System.Security.Cryptography.Rijndael.Create();
crypt.Key = convertedSecureString;
byte[] initializationVectorLength = new byte[sizeof(int)];
CryptoStream cryptostream = new CryptoStream(inputStream, crypt.CreateDecryptor(), CryptoStreamMode.Read);
byte[] buffer = new byte[1024];
int len;
while ((len = cryptostream.Read(buffer, 0, buffer.Length)) > 0)
{
outputStream.Write(buffer, 0, len);
buffer = new byte[1024];
}
outputStream.Flush();
cryptostream.Close();
inputStream.Close();
이제이 코드를 Java/Android와 동일한 것으로 변환해야합니다. 솔직하게 어디에서 시작해야할지 모르겠습니다. 나는 많은 옵션으로 혼란스러워합니다. Bouncy Castle을 사용한다고 말하는 사람들도 있고, Apache Commons가 말하는 일부 Java 원시 라이브러리가 있다고하는 사람들도 있습니다. 어떻게해야합니까? CryptoStream 등은 어떻게해야합니까?
나는 키가 안전 키
byte[] convertedSecureString = new byte[this.key.Length];
IntPtr ptr = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(this.key);
for (int i = 0, j = 0; i < this.key.Length * UnicodeByteLength; i = i + UnicodeByteLength, j++)
{
convertedSecureString[j] = System.Runtime.InteropServices.Marshal.ReadByte(ptr, i);
}
try
{
crypt.Key = convertedSecureString;
}
를 할당하는 C#의 코드를 다음 사용하고
UPDATE. 나는 Java에서 동등한 안전하지 않은 키를 가지고있다. 내가 어떻게 자바
UPDATE
Rfc2898DeriveBytes newKey = new Rfc2898DeriveBytes(crypt.Key.ToString(), crypt.IV);
Array.Copy(newKey.GetBytes((int)crypt.KeySize/8), crypt.Key, (int)crypt.KeySize/8);
Array.Copy(newKey.GetBytes((int)crypt.BlockSize/8), crypt.IV, (int)crypt.BlockSize/8);
에이 코드 조각을 변환합니까 나는 RFC 2898를 사용하여 키를 국방부와 바이트를 유도하기 위해 C#으로이를 사용하고 - 나는 자바에서 동등한를 찾을 수 없습니다 - 두 번째 주석에서 여기 Java equivalent of C#'s Rfc2898DerivedBytes을 발견했습니다. 그러나 iterator와 dklen에 어떤 값을 부여합니까?
고마워요! 그러나 계속 진행하는 방법을 아직 확신 할 수 없습니다. C# 코드에서 수행중인 작업과 동일한 수준의 위 설명에 나를 표시하고 있습니다.암호화 된 데이터 파일을 스트림으로 변환하고, 비트를 해독하고 다시 파일에 쓰는 방법을 모르겠습니다. – Slartibartfast
@Vrashabh : 자바에서 동등한 코드로 답변을 업데이트했습니다. –
도움 주셔서 감사합니다! 그것을 시도하고 조금 더 조사하고 다시 질문을하거나 올바른 대답으로 표시 할 수 있습니다. – Slartibartfast