public static byte[] convertDsaXMLDSIGtoASN1(byte[] xmldsigBytes,int size) throws IOException {
  int totalSize=size * 2;
  if (xmldsigBytes.length != totalSize) {
    throw new IOException("Invalid XMLDSIG format of DSA signature");
  }
  int i;
  for (i=size; i > 0 && xmldsigBytes[size - i] == 0; i--)   ;
  int j=i;
  if (xmldsigBytes[size - i] < 0) {
    j++;
  }
  int k;
  for (k=size; k > 0 && xmldsigBytes[totalSize - k] == 0; k--)   ;
  int l=k;
  if (xmldsigBytes[totalSize - k] < 0) {
    l++;
  }
  byte[] asn1Bytes=new byte[6 + j + l];
  asn1Bytes[0]=48;
  asn1Bytes[1]=(byte)(4 + j + l);
  asn1Bytes[2]=2;
  asn1Bytes[3]=(byte)j;
  System.arraycopy(xmldsigBytes,size - i,asn1Bytes,4 + j - i,i);
  asn1Bytes[4 + j]=2;
  asn1Bytes[5 + j]=(byte)l;
  System.arraycopy(xmldsigBytes,totalSize - k,asn1Bytes,6 + j + l - k,k);
  return asn1Bytes;
}

public static byte [ ] convertDsaXMLDSIGtoASN1 ( byte [ ] xmldsigBytes , int size ) throws IOException { int totalSize = size * 2 ; if ( xmldsigBytes . length != totalSize ) { throw new IOException ( "Invalid XMLDSIG format of DSA signature" ) ; } int i ; for ( i = size ; i > 0 && xmldsigBytes [ size - i ] == 0 ; i -- ) ; int j = i ; if ( xmldsigBytes [ size - i ] < 0 ) { j ++ ; } int k ; for ( k = size ; k > 0 && xmldsigBytes [ totalSize - k ] == 0 ; k -- ) ; int l = k ; if ( xmldsigBytes [ totalSize - k ] < 0 ) { l ++ ; } byte [ ] asn1Bytes = new byte [ 6 + j + l ] ; asn1Bytes [ 0 ] = 48 ; asn1Bytes [ 1 ] = ( byte ) ( 4 + j + l ) ; asn1Bytes [ 2 ] = 2 ; asn1Bytes [ 3 ] = ( byte ) j ; System . arraycopy ( xmldsigBytes , size - i , asn1Bytes , 4 + j - i , i ) ; asn1Bytes [ 4 + j ] = 2 ; asn1Bytes [ 5 + j ] = ( byte ) l ; System . arraycopy ( xmldsigBytes , totalSize - k , asn1Bytes , 6 + j + l - k , k ) ; return asn1Bytes ; }
converts an xml signature dsa value to a asn . 1 dsa value . the jce dsa signature algorithm creates asn . 1 encoded ( r , s ) value pairs ( see section 2 . 2 . 2 of rfc 3279 ) ; the xml signature requires the core biginteger values .
